Re: [Matplotlib-users] mplot3d and daspect

2012-11-02 Thread Alexandr
Benjamin Root  writes:

> 
> 
> On Thu, Jun 9, 2011 at 10:13 AM, Benjamin Root  ou.edu> wrote:
> 
> 
> 
> 
> On Thu, Jun 9, 2011 at 6:25 AM, Richard Hofmeister  wrote:
> Hello mplot3d specialists,I would like to change the aspect ratio of the 3d 
axes similar to matlab's functionality with daspect() or the 'dataaspectratio' 
property of 3d-axes.In the end, the x-y-plane should be non-square due to 
different lengths (not range) of the x and y axis (i know that i can use the 
aspect property of the axes to set the x-z/y-z aspect ratio).There is also the 
package "scitools", which provides all the matlab-3d functions including 
daspect 
via a VTK-backend; that would be my next try.For the simple 3d-plotting without 
fancy shading, i would like to stick to mplot3d:
> 
> 
> 
> Is it possible to change the axis lengths/aspect ratios independently?Richard
> 
> 
> 
> 
> Richard,Good question.  I have never thought about such a feature for 
mplot3d.  Looking back at the code, it does not appear to be feasible to do in 
its current state, as the code seems to assume that the 3d grid is a 
constructed 
from a unit cube.  However, I will see if I can add aspect multipliers to the 
point calculation and get arbitrary aspects.  Maybe I can get that feature 
added 
into the upcoming 1.1.0 release.Ben Root
> 
> 
> 
> 
> Richard,I took a look at how this might be implemented.  There would have to 
be some extra work to make the plots look right when experiencing changes in 
aspect.  I first tried an implementation of just the plot box aspect ratio 
(pbaspect) as a member variable of the axes object.  It will probably turn into 
a property so that I can link it with a daspect value.  Also, the values should 
be normalized to 1, unless you want to see some interesting shrinkage/growth of 
your plot area.Try my branch here: 
https://github.com/WeatherGod/matplotlib/tree/mplot3d/pbaspectAfter building 
that branch, try the following script (shamelessly adapted from some Matlab 
help 
pages for pbaspect and daspect).import matplotlib.pyplot as pltfrom 
mpl_toolkits.mplot3d import Axes3Dimport numpy as npfig = plt.figure()ax = 
fig.gca(projection='3d')x, y = np.mgrid[-2:2:.2, -2:2:.2]z = x * np.exp(-x**2 - 
y**2)
> 
> ax.plot_surface(x, y, z, rstride=1, cstride=1)ax.pbaspect = [1.0, 1.0, 
0.25]plt.show()While this will squash the z-axis nicely, it does not force the 
z-ticks to be pruned, so it gets a little ugly.  However, the axis ticks can be 
changed manually.  Also, with some of my other changes coming soon, it should 
be 
possible for the Axes3D object to automatically adjust the spacing of the tick 
labels so that it is not impacted by the changes in aspect ratio in the 
perpendicular direction (i.e. - the x and y tick labels are closer to the axis 
due to the z-axis scaling).Keep an eye on that branch as I work to improve this 
feature, and feel free to contribute to it as well!Ben Root
> 
> 
> --
> EditLive Enterprise is the world's most technically advanced content
> authoring tool. Experience the power of Track Changes, Inline Image
> Editing and ensure content is compliant with Accessibility Checking.
> http://p.sf.net/sfu/ephox-dev2dev
> 
> ___
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 


Hello!

I am looking for a tool like pbaspect. The only question is how to implement it 
into matplotlib? Do you have a step by step instruction?

Thank you.
Regards,
Alexandr


--
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Figures piling up in Tkinter GUI (1.2.0rc2)

2012-11-02 Thread Vlastimil Brom
2012/11/1 Hans Bering :
> Hello everybody,
>
> I'm building a small Tkinter GUI using matplotlib, in which I have to
> change/update plots quite often depending on user input (with different
> contents & sizes, in different places in the GUI, etc.; but always only
> one figure at a time).
>
> As a first resort, I regenerated the figures with plt.figure(...) whenever
> necessary; unfortunately, the program happily accumulated memory with
> every new figure until the computer would no longer cooperate in a timely
> fashion. The following minimal script should demonstrate the tendency:
>
...
> Now I am wondering if I am missing some detail, e.g., some other clean-up
> procedure? Or should this work & could be a memory leak in matplotlib or
> Tkinter? And/or is this approach (of generating a new figure every time)
> not recommended in the first place? I tried reusing the figure, but some
> aspects like changing the layout in the GUI and applying new size and dpi
> then proved tricky in their own ways.
>
> Many thanks in advance,
> Hans
>
Hi,
I'd recommend to use an embedded plot and only clear and replace its
content (rather than tu use pyplot and recreate the figure multiple
times. I believe, changing of the figure should be possible too.

see e.g. the sample for tkinter
http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html

I only roughly adapted that source to use your function and the memory
usage appears to be more effective (although there is some increase
too - as displayed in Process Explorer). Would some variation of the
following work for you?

hth,
  vbr


#!/usr/bin/env python

import matplotlib
matplotlib.use('TkAgg')
import math

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure

import Tkinter

root = Tkinter.Tk()
root.wm_title("Embedding in TK")

fig = Figure(figsize=(5,4), dpi=100)
ax = fig.add_subplot(111)

canvas = FigureCanvasTkAgg(fig, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)

toolbar = NavigationToolbar2TkAgg( canvas, root )
toolbar.update()
canvas._tkcanvas.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)

plotShift = 0
def replot():
global plotShift, a, f
ax.clear()
xVals = xrange(100)
ax.plot(xVals, [math.sin(x + plotShift) for x in xVals])
fig.canvas.draw()
plotShift += 10

button = Tkinter.Button(master=root, text='replot', command=replot)
button.pack(side=Tkinter.BOTTOM)
Tkinter.mainloop()

--
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] mplot3d and daspect

2012-11-02 Thread Benjamin Root
On Fri, Nov 2, 2012 at 3:18 AM, Alexandr  wrote:

> Benjamin Root  writes:
>
> >
> >
> > On Thu, Jun 9, 2011 at 10:13 AM, Benjamin Root  ou.edu>
> wrote:
> >
> >
> >
> >
> > On Thu, Jun 9, 2011 at 6:25 AM, Richard Hofmeister  3jvuoyhyqgombxhyh7it0rnah6klm...@public.gmane.org> wrote:
> > Hello mplot3d specialists,I would like to change the aspect ratio of the
> 3d
> axes similar to matlab's functionality with daspect() or the
> 'dataaspectratio'
> property of 3d-axes.In the end, the x-y-plane should be non-square due to
> different lengths (not range) of the x and y axis (i know that i can use
> the
> aspect property of the axes to set the x-z/y-z aspect ratio).There is also
> the
> package "scitools", which provides all the matlab-3d functions including
> daspect
> via a VTK-backend; that would be my next try.For the simple 3d-plotting
> without
> fancy shading, i would like to stick to mplot3d:
> >
> >
> >
> > Is it possible to change the axis lengths/aspect ratios
> independently?Richard
> >
> >
> >
> >
> > Richard,Good question.  I have never thought about such a feature for
> mplot3d.  Looking back at the code, it does not appear to be feasible to
> do in
> its current state, as the code seems to assume that the 3d grid is a
> constructed
> from a unit cube.  However, I will see if I can add aspect multipliers to
> the
> point calculation and get arbitrary aspects.  Maybe I can get that feature
> added
> into the upcoming 1.1.0 release.Ben Root
> >
> >
> >
> >
> > Richard,I took a look at how this might be implemented.  There would
> have to
> be some extra work to make the plots look right when experiencing changes
> in
> aspect.  I first tried an implementation of just the plot box aspect ratio
> (pbaspect) as a member variable of the axes object.  It will probably turn
> into
> a property so that I can link it with a daspect value.  Also, the values
> should
> be normalized to 1, unless you want to see some interesting
> shrinkage/growth of
> your plot area.Try my branch here:
> https://github.com/WeatherGod/matplotlib/tree/mplot3d/pbaspectAfterbuilding
> that branch, try the following script (shamelessly adapted from some
> Matlab help
> pages for pbaspect and daspect).import matplotlib.pyplot as pltfrom
> mpl_toolkits.mplot3d import Axes3Dimport numpy as npfig = plt.figure()ax =
> fig.gca(projection='3d')x, y = np.mgrid[-2:2:.2, -2:2:.2]z = x *
> np.exp(-x**2 -
> y**2)
> >
> > ax.plot_surface(x, y, z, rstride=1, cstride=1)ax.pbaspect = [1.0, 1.0,
> 0.25]plt.show()While this will squash the z-axis nicely, it does not force
> the
> z-ticks to be pruned, so it gets a little ugly.  However, the axis ticks
> can be
> changed manually.  Also, with some of my other changes coming soon, it
> should be
> possible for the Axes3D object to automatically adjust the spacing of the
> tick
> labels so that it is not impacted by the changes in aspect ratio in the
> perpendicular direction (i.e. - the x and y tick labels are closer to the
> axis
> due to the z-axis scaling).Keep an eye on that branch as I work to improve
> this
> feature, and feel free to contribute to it as well!Ben Root
> >
> >
> >
> --
> > EditLive Enterprise is the world's most technically advanced content
> > authoring tool. Experience the power of Track Changes, Inline Image
> > Editing and ensure content is compliant with Accessibility Checking.
> > http://p.sf.net/sfu/ephox-dev2dev
> >
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
>
> Hello!
>
> I am looking for a tool like pbaspect. The only question is how to
> implement it
> into matplotlib? Do you have a step by step instruction?
>
> Thank you.
> Regards,
> Alexandr
>
>
I guess there has been enough interest in this feature that I probably
should devote some time to correctly implementing it.  I'll see what I can
do!

Ben Root
--
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users