Re: [Matplotlib-users] How to plot straight lines on polar plots

2009-01-30 Thread John Hunter
On Fri, Jan 30, 2009 at 12:28 AM, jamesf0 jame...@utas.edu.au wrote:

 Sorry, I have done that change, and get these errors:


 Traceback (most recent call last):
  File test7.py, line 36, in module
ax=fig.add_subplot(111, polar=True, resolution=1)
  File /usr/lib/python2.5/site-packages/matplotlib/figure.py, line 676, in
 add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/axes.py, line 6823, in
 __init__
self._axes_class.__init__(self, fig, self.figbox, **kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/projections/polar.py,
 line 171, in __init__
Axes.__init__(self, *args, **kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/axes.py, line 537, in
 __init__
if len(kwargs): martist.setp(self, **kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/artist.py, line 894, in
 setp
func = getattr(o,funcName)
 AttributeError: 'PolarAxesSubplot' object has no attribute 'set_resolution'

What version of mpl are you using?  This should be fixed for releases = 0.98.4

JDH

--
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


Re: [Matplotlib-users] Plot only inside a disc

2009-01-30 Thread Andy.Henshaw

[Christophe] Thanks, your example works but what I must do so to plot for 
example
y=cos x
 ? I'm a very beginner.

  line, = ax.plot(x, np.cos(x))
  patch = patches.Circle((300,300), radius=100)
  line.set_clip_path(patch)

Everything in the matplotlib figure is an Artist (lines, images,
text, rectangles) and you can set the clippath of any artist.  See

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

JDH

This is a very timely question for me.  I'm needing to do something very 
similar, but I need to overlay a semi-transparent rectangle with a hole cut out 
of it.  So, I'm making a rectangular patch, making a circular patch, setting 
the circular patch as the clip region for the rectangular patch, and then 
adding the clipped patch to the plot.  However, I seem to be having trouble 
with the coordinate system, as there is no clipping on the rectangle.

My test code looks like this:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.path as path
import matplotlib.patches as patches

fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(-50,50,0.1)
line, = ax.plot(x, np.cos(x)*50)
r=patches.Rectangle((-10,-10), 20, 20, fc=(0.5,0.5,0.5,0.9))
r.set_zorder(100)

# shouldn't one of these work?
# Plot coordinate system
cutout = patches.Circle((0,0), radius=10)
# Window coordinate system
#~ cutout = patches.Circle((300,300), radius=50)

r.set_clip_path(cutout)
ax.add_patch(r)
plt.show()

--
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


Re: [Matplotlib-users] contour coordinates

2009-01-30 Thread Eli Brosh
Hello again,
I finally found the command I was looking for. It is the to_polygons().
Here is what worked :

# make a LineCollection of contours
col=contour(X,Y,Z,LevelsNumber).collections


for i in np.arange(0,LevelsNumber,1):
polygoni=col[i].get_paths()[0].to_polygons()[0]
print polygoni

All the vertices in each collections are extracted to the polygoni.

Thanks again to Jeff and Patrick !

By the way, I found out that I do not actually need this procedure to
achieve may goal
which was to make a contour plot in ternary coordinates.

Eli



On Tue, Jan 27, 2009 at 11:08 PM, Patrick Marsh patrickmars...@gmail.comwrote:

 On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh ebro...@gmail.com wrote:
  Many thanks to Jeff and to Patric !
  I will try to work along the line suggested by Jeff.
  Patric, please send me your code.
  I hope to learn from it.
 
  Thanks again,
  Eli


 Here is a template that can be used.  I use this for meteorological
 models, but should work with any gridded file.


 import numpy as np
 from mpl_toolkits.basemap import Basemap

 f = (some gridded file)
 X = np.array(grab longitudes from f)
 Y = np.array(grab latitudes from f)
 field = np.array(grab field to be contoured from f)
 map = Basemap(make a Basemap call here)
 level = np.arange(minval, maxval, interval)
 col   = map.contour(X, Y, field, level).collections

 for vertex in col[i].get_paths():# GET THE PATHS FOR THE EACH
 CONTOUR BY LOOPING THROUGH CONTOURS
for vertex in xy.vertices:  # ITERATE OVER THE PATH OBJECTS
x, y = map(vertex[0],vertex[1],inverse=True)   # vertex[0]
 and now 'x' is the longitude of the vertex and vertex[1] and now 'y'
 is the latitude of the vertex


 Let me know how this works.

 -Patrick









 
  On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh patrickmars...@gmail.com
 
  wrote:
 
  On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker jsw...@fastmail.fm
 wrote:
   Eli Brosh wrote:
   Hello,
   I am trying to extract the coordinates of contour lines.
   I tried the following:
  
   cs = *contour*(Z)
   for lev, col in zip(cs.levels, cs.collections):
s = col._segments
  
   that I found in a previous post (title contouring, by Jose
   Gómez-Dans-2 http://www.nabble.com/user/UserProfile.jtp?user=30071
   Nov 30, 2007; 07:47am ) .
  
   I hoped that s will be a list of numpy arrays, each containing the
   (x,y) vertices
   defining a contour line at level lev.
   However, I got an error message:
   AttributeError: 'LineCollection' object has no attribute '_segments'
  
  
   How is it possible to get coordinates of the contours, similar to the
   MATLAB command
[C,H] = *CONTOUR*(...)
   where the result in C is the coordinates of the contours.
  
   A similar question appeared in a post contour data (by Albert Swart
   http://www.nabble.com/user/UserProfile.jtp?user=382945 May 17,
 2006;
   09:42am) but I could not understand the answer.
   Is it possible to get more specific directions with a simple example
 ?
  
  
   Thanks
   Eli
   Eli:  Calling get_paths() on each line collection in CS.collections
 will
   return a list of Path objects.  From the Path objects, you can get a
 Nx2
   array of vertices from the vertices attribute.  There are no
 examples
   that I know of, but if you get it to do what you want to do, it would
 be
   great if you could contribute an example.  As you noted, this question
   has come up several times before.
  
   -Jeff
  
   --
   Jeffrey S. Whitaker Phone  : (303)497-6313
   Meteorologist   FAX: (303)497-6449
   NOAA/OAR/PSD  R/PSD1Email  : jeffrey.s.whita...@noaa.gov
   325 BroadwayOffice : Skaggs Research Cntr 1D-113
   Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg
  
  
  
  
  
 --
   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
  
 
  I'm not sure if this is entirely what you (Eli) are looking for, but I
  have code that will contour model data on a map and then extract the
  lat,lon pairs of all the vertices.  If this is what you are looking
  for, I'm happy to share what I've done.
 
  -Patrick
 
  --
  Patrick Marsh
  Graduate Research Assistant
  School of Meteorology
  University of Oklahoma
  http://www.patricktmarsh.com
 
 



 --
 Patrick Marsh
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma
 http://www.patricktmarsh.com

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.

Re: [Matplotlib-users] Plot only inside a disc

2009-01-30 Thread John Hunter
On Fri, Jan 30, 2009 at 8:54 AM,  andy.hens...@gtri.gatech.edu wrote:

 This is a very timely question for me.  I'm needing to do something very 
 similar, but I need to overlay a semi-transparent rectangle with a hole cut 
 out of it.  So, I'm making a rectangular patch, making a circular patch, 
 setting the circular patch as the clip region for the rectangular patch, and 
 then adding the clipped patch to the plot.  However, I seem to be having 
 trouble with the coordinate system, as there is no clipping on the rectangle.

 My test code looks like this:

 r.set_clip_path(cutout)
 ax.add_patch(r)
 plt.show()


The problem is that the add_patch command is setting the clippath to
the axes bounding box.  I just committed a patch on the branch and
trunk which only sets the clippath to the default if it is not already
set.  If you don't have access to svn, just make the call to
r.set_clip_path *after* you call ax.add_patch.

JDH

--
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


Re: [Matplotlib-users] Plot only inside a disc

2009-01-30 Thread John Hunter
On Fri, Jan 30, 2009 at 10:27 AM,  andy.hens...@gtri.gatech.edu wrote:

 Hmm ... this doesn't quite give me what I'm looking for.  When I do that, I 
 get a semitransparent circle that is clipped to a rectangle.  What I need is 
 a semi-transparent rectangle (with a hole cut out of the middle) that 
 overlays the plot.  The attached graphic demonstrates the concept.

It sounds like what you want is a complex path and may not need to
muck with clipping at all.  Take a look at

http://matplotlib.sourceforge.net/examples/api/donut_demo.html

--
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


Re: [Matplotlib-users] Plot only inside a disc

2009-01-30 Thread Andy.Henshaw


 -Original Message-
 From: John Hunter [mailto:jdh2...@gmail.com]
 Sent: Friday, January 30, 2009 11:29 AM
 To: Henshaw, Andy
 Cc: matplotlib-users@lists.sourceforge.net
 Subject: Re: [Matplotlib-users] Plot only inside a disc

 On Fri, Jan 30, 2009 at 10:27 AM,  andy.hens...@gtri.gatech.edu
 wrote:

  Hmm ... this doesn't quite give me what I'm looking for.  When I do
 that, I get a semitransparent circle that is clipped to a rectangle.
 What I need is a semi-transparent rectangle (with a hole cut out of the
 middle) that overlays the plot.  The attached graphic demonstrates the
 concept.

 It sounds like what you want is a complex path and may not need to
 muck with clipping at all.  Take a look at

 http://matplotlib.sourceforge.net/examples/api/donut_demo.html

Okay, although I wish the clipping was working as I expected, as it looks like 
it would have been **quite a bit** cleaner.  It looks like your svn patch would 
enable me to do what I want with patches, wouldn't you agree?


--
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


Re: [Matplotlib-users] Plot only inside a disc

2009-01-30 Thread Andy.Henshaw


 -Original Message-
 From: andy.hens...@gtri.gatech.edu
 [mailto:andy.hens...@gtri.gatech.edu]
 Sent: Friday, January 30, 2009 11:46 AM
 To: jdh2...@gmail.com
 Cc: matplotlib-users@lists.sourceforge.net
 Subject: Re: [Matplotlib-users] Plot only inside a disc



  -Original Message-
  From: John Hunter [mailto:jdh2...@gmail.com]
  Sent: Friday, January 30, 2009 11:29 AM
  To: Henshaw, Andy
  Cc: matplotlib-users@lists.sourceforge.net
  Subject: Re: [Matplotlib-users] Plot only inside a disc
 
  On Fri, Jan 30, 2009 at 10:27 AM,  andy.hens...@gtri.gatech.edu
  wrote:
 
   Hmm ... this doesn't quite give me what I'm looking for.  When I do
  that, I get a semitransparent circle that is clipped to a rectangle.
  What I need is a semi-transparent rectangle (with a hole cut out of
 the
  middle) that overlays the plot.  The attached graphic demonstrates
 the
  concept.
 
  It sounds like what you want is a complex path and may not need to
  muck with clipping at all.  Take a look at
 
  http://matplotlib.sourceforge.net/examples/api/donut_demo.html


Thanks, that is working quite well, now.

--
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


Re: [Matplotlib-users] [matplotlib-devel] What would you like to see in a book about Matplotlib?

2009-01-30 Thread Chris Walker
Note: Posted to matplotlib-devel and debian-science. 

Sandro, 
   Firstly, good luck with the book. 

The sort of book I'd buy would explain how to use the combination of
matplotlib/ipython/scipy/numpy to analyse data. 

 - what are you using matplotlib for?


I want to use matplotlib/ipython/numpy/scipy for analysis of
experimental data - plotting and fitting models to it. Also perhaps
simulation of the data. 

I have also wanted to use matplotlib to plot data as it was acquired -
see below.

I've not really used matplotlib in anger - but am likely to do so in
the future (and it would have been useful during my PhD had it been
around then).

 - what are the things you like the most of matplotlib, that you want
 to give emphasis to? And why?

Quality plots. The ability to add TeX labels. 

I've been keeping an eye on matplotlib for several years - it looks
good. I really must spend some time exploring it. 

 - what are the (basic) things that, when you were beginning to use
 matplotlib, you wanted to see grouped up but couldn't find?
 - what would you like to see in a book about matplotlib?

Start off by reading data from a file, plotting it and fitting a
function to that data.

Often, several scans are in the same data file. An elegant solution to
reading data something like this example would be useful.

# Scan: 1
# Time: 18:00
# Temperature: 21
# t data
1 12
2 33
3 14
4 40
5 60

# Scan: 2
# Time: 18:02
# Temperature: 30
# t data
1 22
2 33
3 44
4 55

And so on. 


Fitting a function to several data sets - with some of the parameters
fitted to both sets of data and some not would be useful.



 - what are some those advanced feature that made you yell WOW!! ?
 - what are the things you'd like to explore of matplotlib and never
 had time to do?

Plotting with related scales


Sometimes it is useful to plot related scales on x1 and x2 axes. I've
come across this several times in different contexts. In its simplest
form, there is a linear relationship between the axes. In a mechanical test, 
you might want extension on the x1 axis and strain on the x2 axis (for 
example). 

Sometimes there is not a linear relationship. For example you might
want to plot frequency (or photon energy) on x1 and wavelength on x2.

An even more complex example is a Hall-Petch plot:

(Yield Stress) = k/sqrt(Grain Size)

So plotting 1/Sqrt(Grain Size) on the X1 axis gives a linear
plot, but it would be useful to plot the grain size on the X2 scale. 


ipython and emacs
-

Suppose I want to write a script to analyse some data (perhaps I want
a record of what I've done, or perhaps I'd like to perform the same
analysis on several data sets). I'd probably do so in emacs - but it
is useful to do some experimentation in ipython - tab completion is
particularly useful. I feel there must be a good way to do my
experimentation in ipython and save the important bits in emacs - but
I've not sat down and worked out an efficient way of doing this.


Data aqcuisition and experimental control:
-

Writing a simple application to acquire data - ideally from multiple
sources and plot the data as it is acquired. In my case I wanted to
combine mechanical with electrical tests. A couple of interesting
articles by G Varoquaux are listed at
http://wiki.debian.org/DebianScience/DataAcquisition

This is perhaps beyond the scope of the book, but it has come up on
the mailing lists a couple of times. The ideal application would have
a gui for simple use, but a command line (probably ipython) for more
more complex use - perhaps performing a series of tests under
different conditions.


Some discussion of plotting non gridded 2d data should also be in
there.

 
 Your suggestions are really appreciated :) And wish me good luck!

I don't think it is the thrust of your book, but another book I was
looking for is A cookbook of Numerical simulations of classic
physics/engineering problems. For use by physicists/engineers who
don't want to rewrite things from scratch.

Good luck. 

Chris

--
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