Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect savefig size when using size = ( , ) #2303

Open
michaelwang314 opened this issue Dec 5, 2019 · 6 comments
Open

Incorrect savefig size when using size = ( , ) #2303

michaelwang314 opened this issue Dec 5, 2019 · 6 comments

Comments

@michaelwang314
Copy link

michaelwang314 commented Dec 5, 2019

using Plots
gr()

plot(size = (800, 800))
plot!([1, 2], [4, 7])

savefig("TEST.png")

When I run this code, the saved image comes out as the incorrect size 799x800. If instead I do, for example,

plot(size = (600, 600))

I get images of correct size 600x600. While this isn't a big issue, I found that this has some problems with certain codecs when converting a sequence of images, say of size 799x800, to a movie (they require images with even dimensions).

EDIT: If I save as (500, 500), I get a 499x499 image. If I then do (501, 501), I still get 499x499. If I then do (502, 502), I get a 501x501 image. Finally, if I go back to (501, 501), it correctly saves a 501x501 image.

@daschw
Copy link
Member

daschw commented Dec 5, 2019

Thanks for reporting, this is really weird.
@jheinen I think this is an issue on the Plots side, and not with GR, right?

@daschw daschw added the GR label Dec 5, 2019
@michaelwang314
Copy link
Author

michaelwang314 commented Aug 14, 2020

Perhaps not surprisingly, the CirclePlot example on the Animations page with the addition of size --> (800, 800) generates a gif of incorrect size (799, 800). And similarly size --> (500, 500) gives (499, 499), as above.

Just ran some tests with everything updated. I think the last step in my previous tests that gave the correct size might have been an error on my part, though I'm not sure.

using Plots
# saves an image of size (499, 499)
plt = plot(size = (500, 500))
savefig("test1.png")

# saves an image of size (500, 501)
plt = plot(size = (501, 501))
savefig("test2.png")

# saves an image of size (501, 501)
plt = plot(size = (502, 502))
savefig("test3.png")

# saves an image of size (500, 501)
plt = plot(size = (501, 501))
savefig("test4.png")

# saves an image of size (501, 500)
plt = plot(size = (501, 500))
savefig("test5.png")

The last two are a little strange (decreasing the height by 1px fixes the width). I get the same results on my laptop and desktop. Everything seems to be stored fine under the plot attributes plt.attr[:size]. Is the issue with how images/animations are saved (e.g. there's some weird rounding issue when the actual file is generated)?

If I systematically decrease one of the dimensions, say the height, I get

using Plots
cd(dirname(@__FILE__))
for i = 490 : 510
    plot(size = (500, i))
    savefig("test_$i.png")
end
input          output
(500, 490) --> (500, 489)
(500, 491) --> (500, 491) | Good!
(500, 492) --> (500, 492) | Good!
(500, 493) --> (500, 493) | Good!
(500, 494) --> (500, 494) | Good!
(500, 495) --> (500, 495) | Good!
(500, 496) --> (500, 495)
(500, 497) --> (500, 497) | Good!
(500, 498) --> (500, 498) | Good!
(500, 499) --> (500, 499) | Good!
(500, 500) --> (499, 499)
(500, 501) --> (499, 501)
(500, 502) --> (499, 501)
(500, 503) --> (500, 502)
(500, 504) --> (499, 503)
(500, 505) --> (500, 505) | Good!
(500, 506) --> (499, 505)
(500, 507) --> (500, 507) | Good!
(500, 508) --> (499, 508)
(500, 509) --> (500, 509) | Good!
(500, 510) --> (499, 509)

I don't see a pattern...

@BeastyBlacksmith
Copy link
Member

Can you test that with a different backend?

@michaelwang314
Copy link
Author

Can you test that with a different backend?

The above tests were with gr(). With plotly(), all the above tests work fine. With pyplot(), there are some issues but not as many as gr(). Below are the tests with pyplot():

input          output
(500, 490) --> (500, 490) | Good!
(500, 491) --> (500, 491) | Good!
(500, 492) --> (500, 492) | Good!
(500, 493) --> (500, 493) | Good!
(500, 494) --> (500, 494) | Good!
(500, 495) --> (500, 495) | Good!
(500, 496) --> (500, 496) | Good!
(500, 497) --> (500, 497) | Good!
(500, 498) --> (500, 498) | Good!
(500, 499) --> (500, 499) | Good!
(500, 500) --> (500, 500) | Good!
(500, 501) --> (500, 501) | Good!
(500, 502) --> (500, 501)
(500, 503) --> (500, 503) | Good!
(500, 504) --> (500, 504) | Good!
(500, 505) --> (500, 505) | Good!
(500, 506) --> (500, 505)
(500, 507) --> (500, 507) | Good!
(500, 508) --> (500, 508) | Good!
(500, 509) --> (500, 509) | Good!
(500, 510) --> (500, 509)

(800, 800) --> (800, 800) | Good!

@michaelwang314
Copy link
Author

michaelwang314 commented Aug 14, 2020

Oh I forgot one more test with pyplot(). This is the only one that fails:

(502, 502) --> (501, 501) 

@amp1098
Copy link

amp1098 commented Feb 18, 2025

Just sharing that this bug is still present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants