Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: bbox floating point size mismatch #21879

Open
@blatr

Description

@blatr

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp