Re: [Matplotlib-users] Figure save hack

2012-03-16 Thread David Verelst
Hi,

This sounds actually very interesting. I have been thinking about how to 
save matplotlib figures in a way comparable to the Matlab .fig format: a 
file that holds the data (for instance using HDF5/pytables, some figures 
might hold a lot of data) and the plotting commands to exactly 
reconstruct the figure. However, I never got around of thinking about an 
actual implementation for Matplotlib. Hopefully your work can inspire me 
to actually get it started , and I will try to find some time to dig in 
your code the coming weeks.

At the Spyder mailing list the idea of saving figures a la Matlab 
briefly popped before as well: 
http://groups.google.com/group/spyderlib/browse_thread/thread/bf582bac96ff875/d5e94fe9296afbe5
 


I think saving figures in this manner would be a nice feature for 
matplotlib.

Thanks for sharing this!

Regards,
David

PS: sorry to Sebastian for sending the message twice

On 15/03/12 11:22, Sebastian Berg wrote:
> Hey,
>
> last weekend I wrote a hook which can track figure creation. Basically
> it takes care of creating the new figure and wraps it to track all
> changes to it. Its a hack, and the code is not cleaned up or tested
> much, but I like to do scripts that I run with many parameters to create
> plots and it works well to allow me to open the figures in a way that I
> can zoom, etc. and would allow editing (a bit) later on too. So while I
> doubt the approach can be made something serious, and there are probably
> things that don't work (right now 3D Axis can be done with a bit extra
> but mouse zooming does not work inside a 3D Axis, though I think its
> likely not difficult to change), I thought I would put it online because
> I am not aware of any way to save matplotlib figures:
>
> https://github.com/seberg/haunter-for-matplotlib-figures
>
> Maybe someone finds it useful or interesting :)
>
> Regards,
>
> Sebastian Berg
>
>
> --
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] move legend to the foreground: how to use set_zorder() correctly?

2012-03-22 Thread David Verelst
Hi All,

I am plotting on two different y-axes: one on the left (ax1) and one on 
the right (ax2). Both share the same x-axes. The problem I am facing 
relates back to the zorder of the legend (at least, that is what I 
think): I want it to be on the foreground at all times. In order to do 
so, I change the zorder of the ax1.legend (left y axes) such that the 
ax2.plots (right y-axes) are under ax1.legend. However, that doesn't 
work: all the plots on the right axes (so using ax2) end up above the 
legend 1 on the left, despite having a lower zorder.

Note that I am also giving the grids on both ax1 and ax2 a lower zorder 
value compared to the legends, but the grid still ends up on top of 
legend 1 on the left.

# version info:

# Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2

# NumPy 1.6.1, Matplotlib 1.1.0

import pylab as plt

import numpy as np

# plotting on the left y-axes,

ax1 = plt.axes(zorder=10)

ax1.plot(range(0,5,1), 'r', label='ax1 ax1 ax1 ax1', zorder=11)

ax1.plot(np.arange(3,4.1,1), 'r--', label='ax1 ax1 ax1 ax1', zorder=12)

gr1 = ax1.grid(zorder=13)

# legend of the left y-axes, force high zorder

leg1 = ax1.legend(loc='upper left')

leg1.set_zorder(30)

# plotting on the right y-axes,

ax2 = plt.twinx()

ax2.set_zorder(20)

ax2.plot(range(4,-1,-1), 'b', label='ax2 ax2 ax2 ax2', zorder=21)

ax2.plot(np.arange(4,2.9,-1), np.arange(3,4.1,1), 'b--',

label='ax2 ax2 ax2 ax2', zorder=22)

gr2 = ax2.grid(zorder=23)

# legend of the right y-axes, force high zorder

leg2 = ax2.legend(loc='upper right')

leg2.set_zorder(40)

print '=== zorder:'

print ' ax1: %i' % ax1.get_zorder()

print ' ax2: %i' % ax2.get_zorder()

print 'leg1: %i' % leg1.get_zorder()

print 'leg2: %i' % leg2.get_zorder()


What am I missing here?
Thanks,
David



--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] move legend to the foreground

2012-03-22 Thread David Verelst
Hi All,

I am plotting on two different y-axes: one on the left (ax1) and one on 
the right (ax2). Both share the same x-axes. The problem I am facing 
relates back to the zorder of the legend (at least, that is what I 
think): I want it to be on the foreground at all times. In order to do 
so, I change the zorder of the ax1.legend (left y axes) such that the 
ax2.plots (right y-axes) are under ax1.legend. However, that doesn't 
work: all the plots on the right axes (so using ax2) end up above the 
legend 1 on the left, despite having a lower zorder.

Note that I am also giving the grids on both ax1 and ax2 a lower zorder 
value compared to the legends, but the grid still ends up on top of 
legend 1 on the left.

# version info:
# Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2
# NumPy 1.6.1, Matplotlib 1.1.0
import pylab as plt
import numpy as np

# plotting on the left y-axes,
ax1 = plt.axes(zorder=10)
ax1.plot(range(0,5,1), 'r', label='ax1 ax1 ax1 ax1', zorder=11)
ax1.plot(np.arange(3,4.1,1), 'r--', label='ax1 ax1 ax1 ax1', zorder=12)
gr1 = ax1.grid(zorder=13)

# legend of the left y-axes, force high zorder
leg1 = ax1.legend(loc='upper left')
leg1.set_zorder(30)

# plotting on the right y-axes,
ax2 = plt.twinx()
ax2.set_zorder(20)
ax2.plot(range(4,-1,-1), 'b', label='ax2 ax2 ax2 ax2', zorder=21)
ax2.plot(np.arange(4,2.9,-1), np.arange(3,4.1,1), 'b--',
label='ax2 ax2 ax2 ax2', zorder=22)
gr2 = ax2.grid(zorder=23)

# legend of the right y-axes, force high zorder
leg2 = ax2.legend(loc='upper right')
leg2.set_zorder(40)

print '=== zorder:'
print ' ax1: %i' % ax1.get_zorder()
print ' ax2: %i' % ax2.get_zorder()
print 'leg1: %i' % leg1.get_zorder()
print 'leg2: %i' % leg2.get_zorder()

What am I missing here?

Thanks,
David

--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clearing figures from memory

2012-03-24 Thread David Verelst
A while ago I had exactly the same problem. I was running a script that 
create a lot of figures and saved them (as .png and .eps files) for 
viewing later (so not using the interactive viewing feature from 
pyplot). If I remember well, there was also a problem with the close() 
statement leaving some stuff in memory. Unfortunately I don't remember 
how the details went and how it got fixed. I guess I should have used 
the mailing list or created a bug report.

Anyway, when I need to generate a massive amount of figures these days I 
bypass the pyplot interface completely and go straight for the 
matplotlib API (at least as far as I understand this approach myself). 
When using pyplot, some figure tweaks did not persist upon saving, but 
that might as well have been due to my limited matplotlib knowledge. The 
procedure was inspired by this blog post: 
http://sjohannes.wordpress.com/2010/06/11/using-matplotlib-in-a-web-application/
 
and goes as follows:

from matplotlib.figure import Figure
# dependent on the backend you use
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigCanvas
# set figure size, dpi and initiate a workable fig object
fig = Figure(figsize=(figsize_x, figsize_y), dpi=dpi)
canvas = FigCanvas(fig)
fig.set_canvas(canvas)
# tweak white spacings
fig.subplots_adjust(left=wsleft, bottom=wsbottom, right=wsright,
top=wstop, wspace=wspace, hspace=hspace)
# big main title
fig.suptitle(grandtitle, size='x-large')
# create a subplot
ax = fig.add_subplot(nr_rows, nr_cols, plot_nr)

# do all your plotting stuff here on ax

# save the figure and close
fig.savefig('/path/to/figure/figname.png')
canvas.close()
fig.clear()

If interested, I can give you a more elaborate and working example of 
which parameters I tune how exactly.

Regards,
David




On 23/03/12 19:45, Eric Firing wrote:
> On 03/23/2012 08:05 AM, Albert Kottke wrote:
>> I am having problems clearing figures from memory. After saving the
>> figure, I use pyplot.close() on the figure handle and then del all of
>> the data and figure, as shown here:
>>
>> fig.savefig('plots/%(record_id)05i' % recording)
>> plt.close(fig)
>>
>> del accel, fourier_amp, fig, time, disp
>> gc.collect()
>>
>> Despite this, the figures don't appear to be closing. I am trying to
>> make 30k plots and I have to kill script every couple thousand and
>> restart because I run out of memory.
>>
>> Any suggestions?
> You are running a standalone script, correct?  Make sure you are using
> only the agg backend.  Before the first import of pyplot, do
>
> import matplotlib
> matplotlib.use("agg")
>
> I don't know if that will help, but it can't hurt.
>
> You might find matplotlib.cbook.report_memory() to be useful in tracking
> down the problem.
>
> Eric
>
>>
>> Albert
>>
>> --
>> This SF email is sponsosred by:
>> Try Windows Azure free for 90 days Click Here
>> http://p.sf.net/sfu/sfd2d-msazure
>> ___
>> Matplotlib-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> --
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users