Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change resolution of Matplotlib Figure window when saving plot?

I'm using Windows XP v3/Python 2.7 with Canopy and Anaconda package managers/editors.

I am using Python/Matplotlib to produce some Bland-Altman plots (statistical scatter plots) for publication.

After processing the data, the plt.show() command opens a new "Figure" window containing the plot, which looks fine.

I want to be able to use the dynamic pan and zoom commands in this window to interactively optimise the appearance of my plot, then save it as it appears in the window as a high resolution press-quality png image (400-600 dpi, 7 x 5 inches).

The default setting for saving images from the "Figure" window appears to be set to screen resolution (800 x 600 pixels), and I cannot find any options in this window which allow me to change these settings.

I've read other posts on this forum which explain how to directly save a plot from Python in higher resolution by using the following commands to manipulate dpi and image size, e.g.:

plt.figure(figsize=(18, 12), dpi=400)
plt.savefig("myplot.png", dpi = 400)

However, this is not the solution that I'm looking for; as I want to be able to modify the plot using the dynamic pan and zoom features of the "Figure" window before saving in a higher resolution than the default screen resolution.

I'd be grateful for your help.

Many thanks in anticipation & Happy New Year.

Dave (UK)

like image 348
Dave Avatar asked Jan 01 '14 12:01

Dave


1 Answers

Try this:

Determine how to set width and height using a pixels-to-inches converter, like in the following matplotlib documentation. Then try:

import matplotlib.pyplot as plt
fig = plt.figure(frameon=False)
fig.set_size_inches(width,height)
like image 84
Myles Baker Avatar answered Oct 24 '22 07:10

Myles Baker