[Matplotlib-users] axis aspect ratio

2010-03-15 Thread tomislav_ma...@gmx.com
Hello everyone, 

I'm using matplotlib for plotting data results from numerical simulations that 
involve a lot of geometric calculations. 

I did read the tutorial, but I haven't been able to figure out the proper way 
to set the axis aspect ratio to "1" when 
numerical data is plotted. 

Here is an example of my plot:

http://img715.imageshack.us/img715/9318/projections.png

since I need the aspect ratio to be "1" so that I can visually inspect my 
numerical code for bugs, I would really
appreciate the help. 

I've loaded the data using pylab.load and I've plotted the files without using 
figure or axes, just plain old
pyplot.
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] axis aspect ratio

2010-03-15 Thread tomislav_ma...@gmx.com
Thanks a lot! This worked like a charm. I'll need to dig into matplotlib a lot 
later, 
but now I have truckloads of bugs in my code to deal with, this will speed me up
significantly.

Thank you again,

Tomislav
- Original Message -
From: phob...@geosyntec.com
Sent: 03/15/10 05:40 PM
To: tomislav.ma...@gmx.com, matplotlib-users@lists.sourceforge.net
Subject: RE: [Matplotlib-users] axis aspect ratio

Give this a shot:
import matplotlib.pyplot as plt
fig = pl.figure(figsize=(4,4))
ax = fig.add_sublot(1,1,1) # tweak as needed
# [plot your data]
ax.set_aspect(‘equal’)
http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_aspect#matplotlib.axes.Axes.set_aspect
 
http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_aspect#matplotlib.axes.Axes.set_aspect
 

From:tomislav_ma...@gmx.com [mailto:tomislav.ma...@gmx.com] 
Sent: Monday, March 15, 2010 9:33 AM
To:matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] axis aspect ratio
Hello everyone, 
I'm using matplotlib for plotting data results from numerical simulations that 
involve a lot of geometric calculations. 
I did read the tutorial, but I haven't been able to figure out the proper way 
to set the axis aspect ratio to "1" when 
numerical data is plotted. 
Here is an example of my plot:
http://img715.imageshack.us/img715/9318/projections.png 
http://img715.imageshack.us/img715/9318/projections.png 
since I need the aspect ratio to be "1" so that I can visually inspect my 
numerical code for bugs, I would really
appreciate the help. 
I've loaded the data using pylab.load and I've plotted the files without using 
figure or axes, just plain old
pyplot.
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] figure: underlying C/C++ object has been deleted

2010-03-15 Thread tomislav_ma...@gmx.com
Hi, 

I forgot to write something in my last email: I just wish to thank the 
developers of this insanely
great tool. Long live open source. Thank you very much for this, it's the best 
data/graph manipulation 
software ever.

Now, for my question: I'm not sure if I misunderstood something, or is it a bug 
of some sort. 

Here is the code with the error:

http://pastebin.com/3QUws70n


I don't understand, why would a figure object get deleted after it's shown on 
the screen? What am I doing wrong?

Thanks in advance,
Tomislav
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] figure: underlying C/C++ object has been deleted

2010-03-15 Thread tomislav_ma...@gmx.com
Thanks! :D 

Thank you very much. The ipython -pylab is working great! 

Tomislav

P.S.
Enjoy the Hawaiian sunshine... :D I'm freezing in Munich, Germany...
- Original Message -
From: Eric Firing
Sent: 03/15/10 07:59 PM
To: tomislav_ma...@gmx.com
Subject: Re: [Matplotlib-users] figure: underlying C/C++ object has been deleted

tomislav_ma...@gmx.com wrote:
[...]
> 
> Here is the code with the error:
> 
> 
> http://pastebin.com/3QUws70n
> 
> 
> 
> I don't understand, why would a figure object get deleted after it's 
> shown on the screen? What am I doing wrong?

This is a common "gotcha": don't use pyplot.show() anywhere other than 
at the end of a script, and then only when you want the script to 
display a figure and block. For working interactively with ipython 
(which it appears you are doing, and which is recommended), use "ipython 
-pylab". Then, the figure will be redrawn automatically after pyplot 
functions are called. If you use a more OO approach, say using the 
Axes.plot(...) method rather than the pyplot.plot(...) function, you can 
use pyplot.draw() to force an update when you want one.

Eric


> 
> 
> Thanks in advance,
> 
> Tomislav
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] figure: centering data and plot.svg borders

2010-03-17 Thread tomislav_ma...@gmx.com
Hi everyone, 

Is there a straightforward way for me to ensure that my data is 
centered: allways present on the figure? I'm plotting the results
from complicated geometrical calculations and I need high dpi
so that I can debug the code. I've recorded the session in a log
file and I've modified the ipython logfile into a script. The
result is here:

http://img87.imageshack.us/img87/8306/interfaceprojections.png

and the script is here:

http://pastebin.com/3dkfNDuk

As you see, in the image, a part of the rectangle is missing. It is 
actually sort of a rectangle shaped set of finite volumes. What 
I'm looking for is to have the whole rectangle (or any other shape)
visible on the axes of the figure, with a properly scaled axes ratio
('equal' in the script). And to reduce the output, could it be possible
to plot just the diagram, without the remaining whitespace?

It seems that when I use

figureOne.set_figheight(number)
figureOne.set_figwidth(number)

it stands for the figure, but not for the axes. I'm interested just in 
the axes since it's the only subplot. 

Any advice?

I looked in the user guide but I didn't find anything so far... I'll keep
looking.

Thank you in advance,
Tomislav
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] figure: centering data and plot.svg borders

2010-03-18 Thread tomislav_ma...@gmx.com
Thanks, adding the axes ([0,0,1,1]) helped! 
:)
I'll just be careful so that my calculation domain 
is from 0 - 1 in x and y direction, this is something
I have to do anyway. This will definitely work!

Thanks again, 
Tomislav
- Original Message -
From: Friedrich Romstedt
Sent: 03/17/10 07:18 PM
To: tomislav_ma...@gmx.com
Subject: Re: [Matplotlib-users] figure: centering data and plot.svg borders

Maybe:

from matplotlib import pyplot as plt

figureOne = plt.figure()
axesOne = figureOne.add_axes([0, 0, 1, 1])
axesOne.plot([-1, 1], [-2, 2])
axesOne.plot([-2, 2], [-1, 1])

axesOne.set_xlim((-3, 3))
axesOne.set_ylim((-3, 3))
figureOne.set_figwidth(2)
figureOne.set_figheight(2)

plt.savefig("Friedrich.png")

Friedrich
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] how to plot a Polygon / plt.draw() problem

2010-04-11 Thread tomislav_ma...@gmx.com
Hi everyone,

can someone help me to plot a polygon in matplotlib?

I have been reading about the axes.patches.Polygon class and I have defined the
Polygon object that has a preset lw and points. How do I plot it? 

I'm confused because the Axes documentation states that this class holds most 
of 
the figure objects like Rectangle, Line2D, and then the website states that the 
Line2D
is a return object from the plt.plot() invocation. What if I create my own set 
of Rectangle
(Polygon) objects and want to create a list of them and plot them? 

Also, I'm using this sequence of commands to work in OO mode interactively 
(just to learn) but when I execute plt.draw() no figure appears. 

import numpy as np
import matplotlib.pyplot as plt

myFig = plt.figure()
myAx = myFig.add_axes() # I have tried myFig.add_subplot(1,1,1) but it didn't 
help

x = np.arange(0,np.pi, 0.01)
myAx.plot (x, np.sin(x))

plt.draw() # nothing happens

These commands are executed within an interactive ipython session but if I 
start ipython 
with ipython -pylab, plt.draw() draws a figure I can see. I'm running Arch 
linux and Openbox 
as a window manager, the system is 64 bit.
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how to plot a Polygon / plt.draw() problem

2010-04-12 Thread tomislav_ma...@gmx.com
Thank you very much, you helped me a great deal. The video tutorials are great.

I'm going through the stuff you sent and things seem to become clearer 

Tomislav

- Original Message -
From: John Hunter
Sent: 04/11/10 04:19 PM
To: tomislav_ma...@gmx.com
Subject: Re: [Matplotlib-users] how to plot a Polygon / plt.draw() problem

On Sun, Apr 11, 2010 at 7:15 AM, tomislav_ma...@gmx.com
 wrote:
> can someone help me to plot a polygon in matplotlib?
>
> I have been reading about the axes.patches.Polygon class and I have defined
> the
>
> Polygon object that has a preset lw and points. How do I plot it?
>
> I'm confused because the Axes documentation states that this class holds
> most of
>
> the figure objects like Rectangle, Line2D, and then the website states that
> the Line2D
>
> is a return object from the plt.plot() invocation.

Yes, Axes.plot is a helper function which creates a Line2D object,
adds it to the axes, sets the transformation, etc... This process is
covered in some detail in the matplotlib Artist tutorial

 http://matplotlib.sourceforge.net/users/artists.html

and in the advanced matplotlib tutorial at scipy -- video available here

 http://www.archive.org/details/scipy09_advancedTutorialDay1_3

> What if I create my own
> set of Rectangle
>
> (Polygon) objects and want to create a list of them and plot them?

If you create your own polygons/rectangles/patches, create them, and
then add them with Axes.add_patch

 
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.add_patch

If you want to create a bunch of them, consider a PolygonCollection
(or a RegularPolygonCollection depending on your use case)

 http://matplotlib.sourceforge.net/api/collections_api.html
 http://matplotlib.sourceforge.net/search.html?q=codex+PolyCollection

> Also, I'm using this sequence of commands to work in OO mode interactively
>
> (just to learn) but when I execute plt.draw() no figure appears.

We make a distinction between raising a figure (plt.show) and
rendering to an existing figure (plt.draw). In interactive mode
(which is what ipython -pylab turns on) figures are automatically
raised/shown. You can control these settings from a regular python
shell using ion and ioff. See

 http://matplotlib.sourceforge.net/users/shell.html

Here is a complete example::

 import matplotlib.patches as patches
 import matplotlib.pyplot as plt

 fig = plt.figure()
 ax = fig.add_subplot(111)

 verts = [0,0], [0,1], [1,1], [1,0]

 poly = patches.Polygon(verts)

 ax.add_patch(poly)

 ax.set_xlim(-2,2)
 ax.set_ylim(-2,2)

 plt.show()


Hope this helps,
JDH

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] plotting in a loop

2010-04-20 Thread tomislav_ma...@gmx.com
Hello everyone, 

if I read a column file like this (simplified to integers):

0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6

with: "data = np.loadtxt("fileName")", why can't I use a for loop inside 
ipython (started with "-pylab" option) to plot each of the Line2D objects and 
then draw them on the plot? I am using matplotlib to debug a computational 
geometry code and I would like these lines to plot paused by the user input so 
that I can identify when (where) exactly the wrong calculations happen:

import numpy as np
import matplotlib.pyplot as plt
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.set_aspect("equal")
for line in data:
 raw_input("press enter to plot the line")
 ax1.plot([line[0],line[2]],[line[1],line[3]],'b')
 plt.draw()


This way I could see with pressing e.g. the return key when my calculations go 
wrong any advice?
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting in a loop

2010-04-21 Thread tomislav_ma...@gmx.com
Thank you very much Steve! This helped a lot, it worked in the ipython as well, 
there is no difference, only that the ipython is interactive and has more 
supplementary features. :)

Thanks, 
Tomislav
- Original Message -
From: Stephen George
Sent: 04/21/10 03:33 AM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] plotting in a loop

 Hi,

 Sorry haven't used ipython, so not sure if there is another/better ipython way.

 Attached is how I solved it in normal python.
 I added a "next line" button to the graph, and set the ydata for the line each 
time the button is pushed.

 There is a couple of set_ylim lines commented out, depending on the nature of 
your data, it might be appropriate to uncomment one of those, however the 
set_aspect line may might mean the graph is very tall and skinny with the 
supplied data.

 Hope that gives you some ideas for your own code.

 Steve


 On 21/04/2010 3:35 AM, tomislav_ma...@gmx.com wrote: Hello everyone, 

 if I read a column file like this (simplified to integers):

 0 1 2 3
 1 2 3 4
 2 3 4 5
 3 4 5 6

with: "data = np.loadtxt("fileName")", why can't I use a for loop inside 
ipython (started with "-pylab" option) to plot each of the Line2D objects and 
then draw them on the plot? I am using matplotlib to debug a computational 
geometry code and I would like these lines to plot paused by the user input so 
that I can identify when (where) exactly the wrong calculations happen:

import numpy as np
import matplotlib.pyplot as plt
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.set_aspect("equal")
for line in data:
 raw_input("press enter to plot the line")
 ax1.plot([line[0],line[2]],[line[1],line[3]],'b')
 plt.draw()


This way I could see with pressing e.g. the return key when my calculations go 
wrong any advice?


 -- 
Download Intel® Parallel Studio Eval Try the new software tools for 
yourself. Speed compiling, find bugs proactively, and fine-tune applications 
for parallel performance. See why Intel Parallel Studio got high marks during 
beta. http://p.sf.net/sfu/intel-sw-dev http://p.sf.net/sfu/intel-sw-dev  
___ Matplotlib-users mailing list 
matplotlib-us...@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users