-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed as duplicate of#15363
Labels
Description
Bug summary
Hi! matplotlib treats incorrectly floating figsize.
Code for reproduction
import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
import numpy as np
dpi = 100
h = 1708
w = 2560
height_inches = float(h) / dpi
width_inches = float(w) / dpi
fig = 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 in line.
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
Reactions are currently unavailable