Re: [Matplotlib-users] how load data to Image from String?

2008-03-04 Thread sa6113

How use numpy in order to create Image object from string ?
.
.
.
size = canvas.get_width_height(  )
buffer = canvas.tostring_rgb()
img = numpy.empty(size,numpy.uint32)
img = numpy.fromstring(buffer,numpy.uint32)

img is an array , but I want an Image object (without using PIL ).


sa6113 wrote:
 
 Would you please help me ?
 I want to load data to Image (QImage) from String or binary String without
 using PIL module .
 

-- 
View this message in context: 
http://www.nabble.com/how-load-data-to-Image-from-String--tp15784115p15822415.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] How do I get Missing Modules?

2008-03-04 Thread Ssebuliba, J, Mnr [EMAIL PROTECTED]
Hi there,

When I use;

import matplotlib.pyplot as p, 

I get an error message;

ImportError: No module named pyplot. So, how am I supposed to get these missing 
modules?

Please note: I am using Linux (Ubuntu-gusty)!

Regards,
JOE.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] basemap scalebar

2008-03-04 Thread Jeff Whitaker
Michael Hearne wrote:
 Jeff - That would replicate the simple scale-bar from GMT.  Below is 
 my not-complete attempt at replicating the fancy scale bar.  It 
 would need some options for specifying different units (miles, 
 nautical miles, etc.) and perhaps some more attention to spacing of 
 the text from the scale bar and tick marks...

 --Mike

Mike:  Very nice!  Do you want the scale to show the true distance on 
the earth (in which case the labels will vary depending on where the 
label is placed), or the distance in map projection coordinates (in 
which case the labels are constant)?  Or perhaps a lat/lon value could 
be given to specify where the scale is true?

-Jeff

 from numpy import *
 from matplotlib.toolkits.basemap import Basemap, pyproj
 from pylab import *
 # add drawscale method to Basemap class.
 class Basemap2(Basemap):
def drawscale(self,lon,lat,length,yoffset=None):
draw a fancy map scale from lon-length/2,lat-yoffset to
lon-length/2,lat-yoffset, label it with actual distance in km
length = length*1000 #input length is km

#we need 5 sets of x coordinates (in map units)
#center of scale
xc,yc = self(lon,lat)
#left edge of scale
lon1,lat1 = self(xc-length/2,yc,inverse=True)
x1,y1 = self(lon1,lat1)
#quarter scale
lon2,lat2 = self(xc-length/4,yc,inverse=True)
x2,y2 = self(lon2,lat2)
#three quarter scale
lon3,lat3 = self(xc+length/4,yc,inverse=True)
x3,y3 = self(lon3,lat3)
#right edge of scale
lon4,lat4 = self(xc+length/2,yc,inverse=True)
x4,y4 = self(lon4,lat4)

if yoffset is None: yoffset = 0.1*length

#plot top line
ytop = yc+yoffset/2
ybottom = yc-yoffset/2
ytick = ybottom - yoffset/2
ytext = ytick - yoffset/2
m.plot([x1,x4],[ytop,ytop],color='k')
#plot bottom line
m.plot([x1,x4],[ybottom,ybottom],color='k')
#plot left edge
m.plot([x1,x1],[ybottom,ytop],color='k')
#plot right edge
m.plot([x4,x4],[ybottom,ytop],color='k')

#make a filled black box from left edge to 1/4 way across
fill([x1,x2,x2,x1,x1],[ytop,ytop,ybottom,ybottom,ytop],'k')
#make a filled white box from 1/4 way across to 1/2 way across
fill([x2,xc,xc,x2,x2],[ytop,ytop,ybottom,ybottom,ytop],'w')
#make a filled white box from 1/2 way across to 3/4 way across
fill([xc,x3,x3,xc,xc],[ytop,ytop,ybottom,ybottom,ytop],'k')
#make a filled white box from 3/4 way across to end
fill([x3,x4,x4,x3,x3],[ytop,ytop,ybottom,ybottom,ytop],'w')

#plot 3 tick marks at left edge, center, and right edge
m.plot([x1,x1],[ytick,ybottom],color='k')
m.plot([xc,xc],[ytick,ybottom],color='k')
m.plot([x4,x4],[ytick,ybottom],color='k')

#label 3 tick marks
text(x1,ytext,'%d' % (0),\
horizontalalignment='center',\
verticalalignment='top',\
fontsize=9)
text(xc,ytext,'%d' % (round((length/2)/1000)),\
horizontalalignment='center',\
verticalalignment='top',\
fontsize=9)
text(x4,ytext,'%d' % (round((length)/1000)),\
horizontalalignment='center',\
verticalalignment='top',\
fontsize=9)

#put units on top
text(xc,ytop+yoffset/2,'km',\
horizontalalignment='center',\
verticalalignment='bottom',\
fontsize=9)

 # setup of basemap ('lcc' = lambert conformal conic).
 # use major and minor sphere radii from WGS84 ellipsoid.
 m = 
 Basemap2(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
  rsphere=(6378137.00,6356752.3142),\
  resolution='l',area_thresh=1000.,projection='lcc',\
  lat_1=50.,lon_0=-107.)
 # draw coastlines and political boundaries.
 m.drawcoastlines()
 m.fillcontinents()
 # draw parallels and meridians.
 # label on left, right and bottom of map.
 m.drawparallels(arange(0.,80,20.),labels=[1,1,0,1])
 m.drawmeridians(arange(10.,360.,30.),labels=[1,1,0,1])
 # draw a line from x1,y to x2,y and label it with distance in km.
 length = 3000 #kilometers
 x1,y1 = 0.25*m.xmax, 0.25*m.ymax
 lon1,lat1 = m(x1,y1,inverse=True)
 m.drawscale(lon1,lat1,length)
 title('a fancy map scale')
 show()




 --
 Michael Hearne
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 (303) 273-8620
 USGS National Earthquake Information Center
 1711 Illinois St. Golden CO 80401
 Senior Software Engineer
 Synergetics, Inc.
 --




-- 
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC  R/PSD1FAX   : (303)497-6449
325 BroadwayBoulder, CO, USA 80305-3328


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.

Re: [Matplotlib-users] Using math text!

2008-03-04 Thread Michael Droettboom
It looks as if you're using 0.90.1.  All of these issues are fixed in 
0.91.2.  If you can upgrade, that's probably your best bet.

Or, if you have all the requirements, you can set text.usetex to True 
in your matplotlibrc which will use the real TeX on your system to 
typeset math -- that should support your expression.

Ssebuliba, J, Mnr [EMAIL PROTECTED] wrote:
 Hi all,
 
 When I use;
 text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$', fontsize=20)
 
 I get an error message below;
 File /usr/lib/python2.5/site-packages/matplotlib/mathtext.py, line 616, in 
 _get_info
 raise ValueError('unrecognized symbol %s' % sym)
 ValueError: unrecognized symbol \mathr, unrecognized symbol \mathcal

0.90.1 was much less TeX-like in its mathtext support, and therefore 
doesn't support \mathrm, \mathcal etc..  You can, however do:

text(0.6, 0.6, r'$\cal{A}\rm{sin}(2 \omega t)$', fontsize=20)

which works for me.

 When I replace \mathrm with \mbox or \text, the error message I get is 
 basically the same, only that this time, the last line appears as;
 unrecognized symbol \mbox, unrecognized symbol \text

\mbox and \text aren't supported by the built-in mathtext in any version.

Cheers,
Mike

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How do I get Missing Modules?

2008-03-04 Thread Michael Droettboom
Like your last question, I think you're using the current release's 
documentation (0.91.2) with an old release (probably 0.90.1 or earlier).

pyplot did not exist in 0.90.1, but I believe everything that is now in 
pyplot used to be in pylab, so you could just import that instead.

Cheers,
Mike

Ssebuliba, J, Mnr [EMAIL PROTECTED] wrote:
 Hi there,
 
 When I use;
 
 import matplotlib.pyplot as p, 
 
 I get an error message;
 
 ImportError: No module named pyplot. So, how am I supposed to get these 
 missing modules?
 
 Please note: I am using Linux (Ubuntu-gusty)!
 
 Regards,
 JOE.
 
 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2008.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] basemap scalebar

2008-03-04 Thread Michael Hearne
Jeff - I think the way GMT does it would be okay - they have a  
latitude of true scale, which I usually choose as the center latitude  
of the map.


I was thinking we should allow people to choose the simple or  
fancy options.  Do you think it will be okay to have the height of  
the bar and the text offset be relative to the length of it?  I  
suppose if the height becomes a problem, people could use the yoffset  
keyword...


--Mike
On Mar 4, 2008, at 6:05 AM, Jeff Whitaker wrote:


Michael Hearne wrote:
Jeff - That would replicate the simple scale-bar from GMT.   
Below is my not-complete attempt at replicating the fancy scale  
bar.  It would need some options for specifying different units  
(miles, nautical miles, etc.) and perhaps some more attention to  
spacing of the text from the scale bar and tick marks...


--Mike


Mike:  Very nice!  Do you want the scale to show the true distance  
on the earth (in which case the labels will vary depending on where  
the label is placed), or the distance in map projection coordinates  
(in which case the labels are constant)?  Or perhaps a lat/lon  
value could be given to specify where the scale is true?


-Jeff


from numpy import *
from matplotlib.toolkits.basemap import Basemap, pyproj
from pylab import *
# add drawscale method to Basemap class.
class Basemap2(Basemap):
   def drawscale(self,lon,lat,length,yoffset=None):
   draw a fancy map scale from lon-length/2,lat-yoffset to
   lon-length/2,lat-yoffset, label it with actual distance in  
km

   length = length*1000 #input length is km

   #we need 5 sets of x coordinates (in map units)
   #center of scale
   xc,yc = self(lon,lat)
   #left edge of scale
   lon1,lat1 = self(xc-length/2,yc,inverse=True)
   x1,y1 = self(lon1,lat1)
   #quarter scale
   lon2,lat2 = self(xc-length/4,yc,inverse=True)
   x2,y2 = self(lon2,lat2)
   #three quarter scale
   lon3,lat3 = self(xc+length/4,yc,inverse=True)
   x3,y3 = self(lon3,lat3)
   #right edge of scale
   lon4,lat4 = self(xc+length/2,yc,inverse=True)
   x4,y4 = self(lon4,lat4)
  if yoffset is None: yoffset = 0.1*length

   #plot top line
   ytop = yc+yoffset/2
   ybottom = yc-yoffset/2
   ytick = ybottom - yoffset/2
   ytext = ytick - yoffset/2
   m.plot([x1,x4],[ytop,ytop],color='k')
   #plot bottom line
   m.plot([x1,x4],[ybottom,ybottom],color='k')
   #plot left edge
   m.plot([x1,x1],[ybottom,ytop],color='k')
   #plot right edge
   m.plot([x4,x4],[ybottom,ytop],color='k')

   #make a filled black box from left edge to 1/4 way across
   fill([x1,x2,x2,x1,x1],[ytop,ytop,ybottom,ybottom,ytop],'k')
   #make a filled white box from 1/4 way across to 1/2 way across
   fill([x2,xc,xc,x2,x2],[ytop,ytop,ybottom,ybottom,ytop],'w')
   #make a filled white box from 1/2 way across to 3/4 way across
   fill([xc,x3,x3,xc,xc],[ytop,ytop,ybottom,ybottom,ytop],'k')
   #make a filled white box from 3/4 way across to end
   fill([x3,x4,x4,x3,x3],[ytop,ytop,ybottom,ybottom,ytop],'w')
  #plot 3 tick marks at left edge, center, and right edge
   m.plot([x1,x1],[ytick,ybottom],color='k')
   m.plot([xc,xc],[ytick,ybottom],color='k')
   m.plot([x4,x4],[ytick,ybottom],color='k')

   #label 3 tick marks
   text(x1,ytext,'%d' % (0),\
   horizontalalignment='center',\
   verticalalignment='top',\
   fontsize=9)
   text(xc,ytext,'%d' % (round((length/2)/1000)),\
   horizontalalignment='center',\
   verticalalignment='top',\
   fontsize=9)
   text(x4,ytext,'%d' % (round((length)/1000)),\
   horizontalalignment='center',\
   verticalalignment='top',\
   fontsize=9)

   #put units on top
   text(xc,ytop+yoffset/2,'km',\
   horizontalalignment='center',\
   verticalalignment='bottom',\
   fontsize=9)

# setup of basemap ('lcc' = lambert conformal conic).
# use major and minor sphere radii from WGS84 ellipsoid.
m = Basemap2 
(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\

 rsphere=(6378137.00,6356752.3142),\
 resolution='l',area_thresh=1000.,projection='lcc',\
 lat_1=50.,lon_0=-107.)
# draw coastlines and political boundaries.
m.drawcoastlines()
m.fillcontinents()
# draw parallels and meridians.
# label on left, right and bottom of map.
m.drawparallels(arange(0.,80,20.),labels=[1,1,0,1])
m.drawmeridians(arange(10.,360.,30.),labels=[1,1,0,1])
# draw a line from x1,y to x2,y and label it with distance in km.
length = 3000 #kilometers
x1,y1 = 0.25*m.xmax, 0.25*m.ymax
lon1,lat1 = m(x1,y1,inverse=True)
m.drawscale(lon1,lat1,length)
title('a fancy map scale')
show()




--
Michael Hearne
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.

[Matplotlib-users] newbie question about interactive plotting

2008-03-04 Thread David Fox
I'm trying to use the pylab interface of matplotlib interactively.  I'd
like to enter some commands interactively to generate some data, plot a
graph based on the data, inspect the graph, enter more interactive
python, plot another graph, and so on.  Instead, what happens is either

(a) If I start with matplotlib set to interactive, control returns to
the Idle shell after the graph appears, but my graph window isn't
interactive (and most importantly, the window doesn't even refresh
properly, so if it is initially covered by the Idle window or another
window, that part of the graph isn't visible even when I put the graph
window in the foreground, or

(b) if I don't start with matplotlib in interactive mode, then to see
the graph I need to type show().   Then the graph is interactive and
refreshing works right, but the cursor doesn't return to the Idle shell,
unless I kill the graph window.  At that point, any subsequent calls to
show() behave as in case (a).

My questions are:

1.  Is this the expected behavior? [given the details on my setup and
procedure below]
2.  Is there a way to get the type of interactivity I described in the
first paragraph of my email, other than using ipython (which I don't
particularly like because of the DOS window display, and the lack of
command completion and function argument hints which I depend on when
using GUI python shells like pythonwin or PyCrust)? 
3.  Is this a fundamental issue with trying to plot using an interactive
shell whose main message loop doesn't know anything about the graph
window?

I suspect the answers are yes, no (except ipython), and yes, but if so,
I'd like to have confirmation of that so I don't keep trying to bang my
head against a wall trying to figure out what I'm doing wrong.

Here are the details on what versions I'm running and what I'm trying:

I'm using matplotlib version 0.91.2 with Python 2.4.4 on Windows XP.
Following the instructions at
http://matplotlib.sourceforge.net/interactive.html, I've set my TkAgg as
my default backend and set interactive to True in my matplotlibrc file.

I generally like do my interactive python in a shell with
autocompletion.  On Windows, I generally prefer PythonWin, but am open
to exploring others if PythonWin is not going to be compatible with the
matplotlib backend.  For now, I'm testing with the (Tkinter-based) Idle
to avoid possible conflicts between the PythonWin mainloop.

I fire up Idle and following the example, type

  from pylab import *
  plot([1,2,3])

A new window pops up and displays my graph.  However, the toolbar in the
window does not respond, and any portion of the window which was covered
by my Idle window doesn't get refreshed when I switch to the window.
This is not terribly useful.

Alternatively, if I don't set interactive in matplotlibrc, I do the same
steps and an empty window pops up.  If I then type

  show()

the graph appears in that window, and refreshing and the toolbar work
fine.

I can manipulate the window and its contents with the toolbar.  However,
the cursor does not return to the Idle window, so I can't plot another
graph.  The only way I've been able to get the cursor to return to the
Idle window is to close the graph window (via the Windows close button).
When I do that, I can once again issue python commands interactively,
and the behavior again matches the interactive mode (so refresh doesn't
work right).

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how load data to Image from String?

2008-03-04 Thread sa6113

I need QImage in order to display or use in GUI , for exa. in QFrame or
QLabel , I can convert the Image to QImage , but the problem is that I
haven't access to Image object without saving that , also I can convert the
figure (Plot) to string or buffer but I don't know what should I do after
that and how convert it to Image.
 
What about numpy or Numerical Python , may I use fromstring or another
function ?
Or what about savining the string binary or buffer in StringIO and then
convert to QImage ?



Christopher Barker wrote:
 
 sa6113 wrote:
 Would you please help me ?
 I want to load data to Image (QImage) from String or binary String
 without
 using PIL module .
 
 you can load data straight into a numpy array with numpy.fromstring() -- 
 if it's in an easy format (RGB, RGBA), then you should be able to go 
 from there.
 
 What do you want to do with the image data?
 
 -CHB
 
 
 -- 
 Christopher Barker, Ph.D.
 Oceanographer
 
 Emergency Response Division
 NOAA/NOS/ORR(206) 526-6959   voice
 7600 Sand Point Way NE   (206) 526-6329   fax
 Seattle, WA  98115   (206) 526-6317   main reception
 
 [EMAIL PROTECTED]
 
 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2008.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 

-- 
View this message in context: 
http://www.nabble.com/how-load-data-to-Image-from-String--tp15784115p15843273.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users