creating figures of exact size

Friends,

I am trying to make a figure for publication. I am making a double column figure of 7inch as per journal guidelines. The figure comes out nicely but the final size of the figure that is saved is not what i have given in ‘figsize’. It is 10inch X 5.38 inch. How can i make mpl to create the figure of exact size and resolution?

fig=plt.figure(figsize=(7,4))
fig.subplots_adjust(wspace=0.1,hspace=0.1)
ax1=fig.add_subplot(221)
ax2=fig.add_subplot(222,sharex=ax1,sharey=ax1)
ax3=fig.add_subplot(223,sharex=ax1,sharey=ax1)
ax4=fig.add_subplot(224,sharex=ax1,sharey=ax1)

Thanks,
Bala

Hello everyone.

If I try to use LaTeX for text processing (i.e. text.usetex : True in my matplotlibrc), I get a cryptic LaTeX error which didn't use to be there before. I get the same problem when using matplotlib-0.98.5 which I compiled from source, and matplotlib-1.0.0 from macports. My python version is 2.6.5 (from macports) and I am running Mac OS X 10.6.4.

The error messages are pretty much the same no matter what I plot, and everything works fine if text.usetex : False.

Regards
Paul.

usetex_fonteffects.py (783 Bytes)

That's strange. I don't see any problems with the figure size on my system. This may seem like a silly question, but do you have the same sizing issue for the following code:

import matplotlib.pyplot as plt
fig=plt.figure(figsize=(7,4))
fig.subplots_adjust(wspace=0.1,hspace=0.1)
ax1=fig.add_subplot(221)
ax2=fig.add_subplot(222,sharex=ax1,sharey=ax1)
ax3=fig.add_subplot(223,sharex=ax1,sharey=ax1)
ax4=fig.add_subplot(224,sharex=ax1,sharey=ax1)
plt.savefig('test.pdf')
# works fine on my system with png, pdf, and eps

I just want to make sure you aren't altering the figure in any other way before you save.

Are you using savefig or are you saving from a GUI window? Are you on a current version of matplotlib (if yes, you might be interested in `plt.subplots` to create your axes)? What image format are you using?

-Tony

···

On Aug 17, 2010, at 11:02 AM, Bala subramanian wrote:

Friends,

I am trying to make a figure for publication. I am making a double column figure of 7inch as per journal guidelines. The figure comes out nicely but the final size of the figure that is saved is not what i have given in 'figsize'. It is 10inch X 5.38 inch. How can i make mpl to create the figure of exact size and resolution?

fig=plt.figure(figsize=(7,4))
fig.subplots_adjust(wspace=0.1,hspace=0.1)
ax1=fig.add_subplot(221)
ax2=fig.add_subplot(222,sharex=ax1,sharey=ax1)
ax3=fig.add_subplot(223,sharex=ax1,sharey=ax1)
ax4=fig.add_subplot(224,sharex=ax1,sharey=ax1)

Thanks,
Bala

Hi Tony,
My mpl version is 0.98.5.2. I saved the figure using GUI. I just tried saving with savefig function. In that case, the size of the figure is exactly what i gave in figsize arguement. You question helped me. Thank you.

Thanks,
Bala

···

On Tue, Aug 17, 2010 at 5:50 PM, Tony S Yu <tsyu80@…287…> wrote:

On Aug 17, 2010, at 11:02 AM, Bala subramanian wrote:

Friends,

I am trying to make a figure for publication. I am making a double column figure of 7inch as per journal guidelines. The figure comes out nicely but the final size of the figure that is saved is not what i have given in ‘figsize’. It is 10inch X 5.38 inch. How can i make mpl to create the figure of exact size and resolution?

fig=plt.figure(figsize=(7,4))

fig.subplots_adjust(wspace=0.1,hspace=0.1)

ax1=fig.add_subplot(221)

ax2=fig.add_subplot(222,sharex=ax1,sharey=ax1)

ax3=fig.add_subplot(223,sharex=ax1,sharey=ax1)

ax4=fig.add_subplot(224,sharex=ax1,sharey=ax1)

Thanks,

Bala

That’s strange. I don’t see any problems with the figure size on my system. This may seem like a silly question, but do you have the same sizing issue for the following code:

import matplotlib.pyplot as plt
fig=plt.figure(figsize=(7,4))

fig.subplots_adjust(wspace=0.1,hspace=0.1)

ax1=fig.add_subplot(221)

ax2=fig.add_subplot(222,sharex=ax1,sharey=ax1)

ax3=fig.add_subplot(223,sharex=ax1,sharey=ax1)

ax4=fig.add_subplot(224,sharex=ax1,sharey=ax1)

plt.savefig(‘test.pdf’)

works fine on my system with png, pdf, and eps

I just want to make sure you aren’t altering the figure in any other way before you save.

Are you using savefig or are you saving from a GUI window? Are you on a current version of matplotlib (if yes, you might be interested in plt.subplots to create your axes)? What image format are you using?

-Tony

2010/8/17 Paul Anton Letnes <paul.anton.letnes@...287...>:

If I try to use LaTeX for text processing (i.e. text.usetex : True in my matplotlibrc), I get a cryptic LaTeX error which didn't use to be there before. I get the same problem when using matplotlib-0.98.5 which I compiled from source, and matplotlib-1.0.0 from macports. My python version is 2.6.5 (from macports) and I am running Mac OS X 10.6.4.

The error messages are pretty much the same no matter what I plot, and everything works fine if text.usetex : False.

Can't reproduce the error here on Mac OS X 10.6.4 64bit with
framework-compiled Python 2.6.5 and matplotlib from svn. I could
imaging you are missing file creation rights or similar in the
directory where matplotlib wants to place that foobar123345.tex file.

Friedrich

It seems that I had changed an environment variable (TEXINPUTS) elsewhere, meaning that latex didn't pick up the right source file. Everything seems fine now!

Paul

···

On 18. aug. 2010, at 23.21, Friedrich Romstedt wrote:

2010/8/17 Paul Anton Letnes <paul.anton.letnes@...287...>:

If I try to use LaTeX for text processing (i.e. text.usetex : True in my matplotlibrc), I get a cryptic LaTeX error which didn't use to be there before. I get the same problem when using matplotlib-0.98.5 which I compiled from source, and matplotlib-1.0.0 from macports. My python version is 2.6.5 (from macports) and I am running Mac OS X 10.6.4.

The error messages are pretty much the same no matter what I plot, and everything works fine if text.usetex : False.

Can't reproduce the error here on Mac OS X 10.6.4 64bit with
framework-compiled Python 2.6.5 and matplotlib from svn. I could
imaging you are missing file creation rights or similar in the
directory where matplotlib wants to place that foobar123345.tex file.

Friedrich