Skip to content

FIX save_image() dpi #241

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

Merged
merged 1 commit into from
Jun 4, 2018
Merged

FIX save_image() dpi #241

merged 1 commit into from
Jun 4, 2018

Conversation

christianbrodbeck
Copy link
Collaborator

When setting different DPI in rcParams saved images are wrongly scaled (see below). I suspect it's because unlike matplotlib's imsave, PySurfer does not use dpi when saving the image. This PR fixes this.

old rh wrong

@agramfort
Copy link
Contributor

ok for you @mwaskom ?

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@baca853). Click here to learn what that means.
The diff coverage is 50%.

@@            Coverage Diff            @@
##             master     #241   +/-   ##
=========================================
  Coverage          ?   64.86%           
=========================================
  Files             ?        7           
  Lines             ?     2479           
  Branches          ?      494           
=========================================
  Hits              ?     1608           
  Misses            ?      688           
  Partials          ?      183

@mwaskom
Copy link
Member

mwaskom commented Jun 4, 2018

I don't think I fully understand the failure mode here or how the PR fixes it? Could you code up a simple example to demonstrate it, ideally skipping PySurfer and just plotting a random image?

@larsoner
Copy link
Contributor

larsoner commented Jun 4, 2018

I think we either need to pass dpi=100 to both the Figure constructor and in savefig, or in neither place (the latter is implemented here, and seems cleaner).

IIUC currently we set dpi in one place, and always to 100, so in the other place it presumably takes the DPI value from plt.rcParams. So in theory doing a plt.rc_context with a wildly different DPI followed by a brain.save_image(...) should show something like what @christianbrodbeck posted at the top.

@mwaskom
Copy link
Member

mwaskom commented Jun 4, 2018

There are two different matplotlib rcParams that set the dpi (figure.dpi and savefig.dpi) ... maybe that's the issue?

I think we should give users a way to set the DPI of their figure in a way that doesn't involve matplotlib rcParams. It won't at all be obvious why those would be relevant, and when making figures for a paper, you'll generally want a higher DPI than the matplotlib default of 72.

@larsoner
Copy link
Contributor

larsoner commented Jun 4, 2018

Fine by me to have dpi kwarg to savefig to set the output DPI

@christianbrodbeck
Copy link
Collaborator Author

christianbrodbeck commented Jun 4, 2018 via email

@mwaskom
Copy link
Member

mwaskom commented Jun 4, 2018

I guess that's a good point ... if we're limited by the DPI of the mayavi screenshot bitmap maybe it doesn't make sense to give the impression you could boost that further when saving an image file.

@larsoner
Copy link
Contributor

larsoner commented Jun 4, 2018

True, and advanced users can still set the image metadata with plt.rc_context if they want

@larsoner larsoner merged commit d90fdff into nipy:master Jun 4, 2018
@larsoner
Copy link
Contributor

larsoner commented Jun 4, 2018

Thanks @christianbrodbeck

@christianbrodbeck christianbrodbeck deleted the dpi branch June 5, 2018 20:34
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.

5 participants