confused by savefig.dpi and how can I set the dpi of jpeg format?

Dear all,

I searched the internet but still get confused by how can I save a figure with high dpi value to jpeg format.

I am using matplotlib 1.2.0 with ubuntu system.
In [14]: mat.version
Out[14]: ‘1.2.0’

I tried both setting the flag “savefig.dpi” flag in matplotlibrc as 300,
and use fig.savefig(‘temp.jpg’,dpi=300) when saving the figure.
But when I checked the figure dpi with GIMP, it says 72.

Under Windows system, it also says the dpi is 72.
In the example above, the “figure.dpi” value is 80.
In [21]: mat.rcParams[‘figure.dpi’]
Out[21]: 80

I tried to set the “figure.dpi” as 300, But then when I check the figure with interactive window

(I use GTKAgg backend), the figure is too big (getting out of the screen) to veiw. [But I think this
is fine as the figure size will be depend on dpi, No?]

My workflow is like I always make plot in the interactive mode,
then I adjust the figure size (by draging) or the vertical space and other things.
Then I click the save button on the interative window or use
“fig = gcf(); fig.savefig” command to save when I feel comfortable with the figure.

I never published yet and now is working on my first one. So I don’t know if this procedure is good or not.
but anyway, how can I save jpg figures with dpi >300 with the normal size I see on the screen?

thanks for the help,

Chao

···


Chao YUE
Laboratoire des Sciences du Climat et de l’Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex

Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16


2013/3/11 Chao YUE <chaoyuejoy@...287...>:

Dear all,

I searched the internet but still get confused by how can I save a figure
with high dpi value to jpeg format.

I am using matplotlib 1.2.0 with ubuntu system.
In [14]: mat.__version__
Out[14]: '1.2.0'

I tried both setting the flag "savefig.dpi" flag in matplotlibrc as 300,
and use fig.savefig('temp.jpg',dpi=300) when saving the figure.
But when I checked the figure dpi with GIMP, it says 72.

I can replicate this, but saving as png I get the correct dpi. I don't
know if this is a bug or a limitation of the jpg format.

Anyway, the jpg and png images are made of the same number of pixels
hence the dpi should not be an issue provided you can scale the image
in your publishing software. And the png format will do better in many
cases.

Goyo

Dear Goyo,

Thanks for your information. I finally change them into pdf but not used yet.
Otherwise I will try png format.

cheers,

Chao

···

On Wed, Mar 13, 2013 at 6:54 PM, Goyo <goyodiaz@…287…> wrote:

2013/3/11 Chao YUE <chaoyuejoy@…287…>:

Dear all,

I searched the internet but still get confused by how can I save a figure

with high dpi value to jpeg format.

I am using matplotlib 1.2.0 with ubuntu system.

In [14]: mat.version

Out[14]: ‘1.2.0’

I tried both setting the flag “savefig.dpi” flag in matplotlibrc as 300,

and use fig.savefig(‘temp.jpg’,dpi=300) when saving the figure.

But when I checked the figure dpi with GIMP, it says 72.

I can replicate this, but saving as png I get the correct dpi. I don’t

know if this is a bug or a limitation of the jpg format.

Anyway, the jpg and png images are made of the same number of pixels

hence the dpi should not be an issue provided you can scale the image

in your publishing software. And the png format will do better in many

cases.

Goyo


Chao YUE
Laboratoire des Sciences du Climat et de l’Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex

Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16