X Tutup
Skip to content

Use rounding instead of truncation to calculate the frame size#8250

Closed
ngoldbaum wants to merge 1 commit intomatplotlib:masterfrom
ngoldbaum:frame-size-round
Closed

Use rounding instead of truncation to calculate the frame size#8250
ngoldbaum wants to merge 1 commit intomatplotlib:masterfrom
ngoldbaum:frame-size-round

Conversation

@ngoldbaum
Copy link
Copy Markdown
Contributor

This fixes an issue I ran into where the frame sizes were supposed to be adjusted to integers by _adjust_frame_size, but because the frame_size property uses truncation, the vagaries of floating point math means that the frame size adjustment didn't work. Here's a snippet from my debugging session that illustrates the issue:

(Pdb) self.fig.get_size_inches()[1]*self.dpi
919.99999999999989

I think it's safe just to use rounding here instead of truncation? Maybe we need to add epsilon somewhere instead if this could cause issues.

Yay floating point math!

'A tuple (width,height) in pixels of a movie frame.'
w, h = self.fig.get_size_inches()
return int(w * self.dpi), int(h * self.dpi)
return round(w * self.dpi), round(h * self.dpi)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use np.round? Otherwise, the behavior is Python version-dependent.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity to Nathan, you mean np.round([w * self.dpi, h * self.dpi]), right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(tuple of numpy scalars vs numpy array)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result (according to the docstring) should still be a tuple.

@ngoldbaum
Copy link
Copy Markdown
Contributor Author

Apologies for the noise, this isn't actually right - I get this out the other end:

http://imgur.com/a/SWcPI

(which is among the weirdest results of a bug I've run into in a while).

Will try to dig in and figure out what the real fix is....

@ngoldbaum
Copy link
Copy Markdown
Contributor Author

I have an alternate fix for this that I will open another pull request for

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup