using savefig to save plot in desired size

Hello,

It may be a very basic question, but I could not find the solution in archives or the documentation. I need to make a line plot (in square aspect ratio) and then save the figure which is also square in size, i.e. like 600x600 pixels and not 800x600. How can I acheive this?

to get the square axes, I used

ax.set_aspect(1./ax.get_data_ratio())

but I have no idea how to save the fig also in a square format.

thanks in advance,

stupid me…

I found the solution which is to use figure parametrs…

rcParams[‘figure.figsize’] = (6,6)

or something like that… well now I extend my question , i.e., how to make sure that my axis labels are not truncated due to this?

···

On Mon, Jan 26, 2009 at 8:21 AM, Abhinav Verma <abhinav1205@…287…> wrote:

Hello,

It may be a very basic question, but I could not find the solution in archives or the documentation. I need to make a line plot (in square aspect ratio) and then save the figure which is also square in size, i.e. like 600x600 pixels and not 800x600. How can I acheive this?

to get the square axes, I used

ax.set_aspect(1./ax.get_data_ratio())

but I have no idea how to save the fig also in a square format.

thanks in advance,

Abhinav Verma wrote:

Hello,

It may be a very basic question, but I could not find the solution in archives or the documentation. I need to make a line plot (in square aspect ratio) and then save the figure which is also square in size, i.e. like 600x600 pixels and not 800x600. How can I acheive this?

to get the square axes, I used

ax.set_aspect(1./ax.get_data_ratio())

I think what you want here may be something like

fig = figure(figsize=(6, 6), dpi=100)
ax = fig.add_subplot(1,1,1)
[... plotting commands]
ax.set_aspect('equal', adjustable='box')
fig.savefig('mysquarefig.png', dpi=100)

Eric

···

but I have no idea how to save the fig also in a square format.

thanks in advance,

------------------------------------------------------------------------

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Yes Eric this is what I wanted and Many thanks for your help.

My question now extends a little. Due to this … my yaxis label is truncated in the png. How can I make sure that my figure is square and also contains everything. Is it possilbe?

Thanks again,

···

On Mon, Jan 26, 2009 at 8:42 AM, Eric Firing <efiring@…202…> wrote:

Abhinav Verma wrote:

Hello,

It may be a very basic question, but I could not find the solution in archives or the documentation. I need to make a line plot (in square aspect ratio) and then save the figure which is also square in size, i.e. like 600x600 pixels and not 800x600. How can I acheive this?

to get the square axes, I used

ax.set_aspect(1./ax.get_data_ratio())

I think what you want here may be something like

fig = figure(figsize=(6, 6), dpi=100)

ax = fig.add_subplot(1,1,1)

[… plotting commands]

ax.set_aspect(‘equal’, adjustable=‘box’)

fig.savefig(‘mysquarefig.png’, dpi=100)

Eric

but I have no idea how to save the fig also in a square format.

thanks in advance,



This SF.net email is sponsored by:

SourcForge Community

SourceForge wants to tell your story.

http://p.sf.net/sfu/sf-spreadtheword



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Abhinav Verma wrote:

Yes Eric this is what I wanted and Many thanks for your help.

My question now extends a little. Due to this .. my yaxis label is truncated in the png. How can I make sure that my figure is square and also contains everything. Is it possilbe?

There is no standard automatic method; you have to adjust the position of the axes within the figure. You can either specify the position explicitly by using

ax = fig.add_axes([l,b,w,h]

in place of add_subplot, and with l, b, w, h being left, bottom, width, and height in normalized coordinates (i.e., fractions of the figure window), or you can use fig.add_subplot together with fig.subplots_adjust(**kwargs).

Either way, to figure out how to set the l,b,w,h, you can first make the plot interactively and use the "Configure subplots" tool (next to last on the right) in the toolbar to interactively adjust the axes position and to show you what the values are that make it look right.

The default axes and subplot positioning parameters are also available via rcParams.

Eric