Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
Hi! matplotlib treats incorrectly floating figsize.
Code for reproduction
importmatplotlib.pyplotaspltfrommatplotlib.backends.backend_aggimportFigureCanvasAggasFigureCanvasimportnumpyasnpdpi=100h=1708w=2560height_inches=float(h)/dpiwidth_inches=float(w)/dpifig=plt.figure(figsize=(width_inches,height_inches),dpi=dpi)plt.axes([0,0,1,1])plt.axis("off")canvas=FigureCanvas(fig)extent= (0,2560,1708,0)plt.imshow(np.zeros((2560,1708,3)),extent=extent)canvas.draw()fig.clear()plt.close(fig)original_image=np.fromstring(canvas.tostring_rgb(),dtype="uint8").reshape(h,w,3)
Actual outcome
ValueError: cannot reshape array of size 13109760 into shape (1708,2560,3)
Expected outcome
array of size (1708,2560,3)
Additional information
Problem appears from rounding error in variable "height_inches" which results in wrong argument inline.
At this line width is equal to 1707.9999999999998 and int(1707.9999999999998)=1707 but not 1708 as expected
Operating system
Ubuntu 18.04.5 LTS (Bionic Beaver)
Matplotlib Version
3.3.4
Matplotlib Backend
agg
Python version
3.7.10
Jupyter version
No response
Installation
conda