Re: [Matplotlib-users] Vertical alignment of a text

2009-01-16 Thread projetmbc
Title: Flashmail




Thanks, that's work well.
 
Regards.
C.
 
 
>I presume that you're only interested in the math formula, and not in >any other graphical functionality of MPL. You may use mathtext module >directly in that case. > >from matplotlib.mathtext import MathTextParser > >p = MathTextParser("bitmap") >filename, texstr = "test.png", r"$\alpha$" >p.to_png(filename, texstr) >d = p.get_depth(texstr)


--
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] Color Map.

2009-01-16 Thread projetmbc
Title: Flashmail




Thanks,
that's look great.
 
Regards.
C.
 
>Unfortunately, I don't use Mayavi and therefore don't have any easy >examples to offer. I guess you might find such things in the user >guide or Cookbook. > >http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/ >http://www.scipy.org/Cookbook/MayaVi > >Cheers, >Scott 


--
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() cuts off long tick labels

2009-01-16 Thread John Hunter


On Jan 15, 2009, at 8:41 PM, Eric Firing  wrote:

> Chris Fonnesbeck wrote:
>> Is there any way of preventing tick label names from being cut off by
>> the plot canvas? Seems to happen every time:
>>
>> http://a3.s3.p.quickshareit.com/files/validationb0e66.png
>>
>> Thanks in advance.
>>
>
> There is no automatic way.  If you are going to use long labels like
> that, then you need to use subplots_adjust or other manual methods for
> positioning your axes within your figure.

You can also permanently change the defaults in you rc file

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] Figure with pyQt

2009-01-16 Thread B Clowers

You'll have to excuse some of the comments in the code (it's in a constant 
state of revision), but this is a basic PyQt4/matplotlib widget that I use 
quite often and can be embedded using QtDesigner as well.  You'll obviously 
need PyQt4, Matplotlib, and Numpy to run it.  Of course mods can be made as you 
see fit for your particular application.  

I should note that Ctrl+Z zooms using the Spanselector and the top of the drawn 
span is the max Y and the the min Y always defaults to 0 (this works for my 
data sets).  Ctrl+A zooms out.  Save to csv is also an option 
(Ctrl+Alt+S)--this can fail if you've a weird data set. Ctrl+C copies a png of 
the current figure to the user's home directory (works for both Linux and 
Windows) and also puts the image on the current clipboard.  

I've also added an option to make multiple plot layouts that are stored in a 
dictionary that can be accessed to plot to the given axes.  If anyone has a 
more elegant solution please share.  Let me know if you've questions.

Cheers,

Brian

##
#!/usr/bin/env python

 
import os

import sys

 
from PyQt4 import QtCore,  QtGui

 
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as 
NavigationToolbar

#from matplotlib.backend_bases import NavigationToolbar2

 
from matplotlib.figure import Figure

 
from matplotlib.widgets import SpanSelector

#from matplotlib.pyplot import savefig

 
import numpy as N

 
 
class MyMplCanvas(FigureCanvas):

    def __init__(self, parent=None, width = 5, height = 5, dpi = 100, sharex = 
None, sharey = None):

    self.fig = Figure(figsize = (width, height), dpi=dpi, facecolor = 
'#FF')

    self.axDict = {}

    self.figInit = False

 
    self.sharey = sharey

    self.sharey = sharey

 
#    self.ax1.hold(True)

 
 
    FigureCanvas.__init__(self, self.fig)

    #self.fc = FigureCanvas(self.fig)

    FigureCanvas.setSizePolicy(self,

    QtGui.QSizePolicy.Expanding,

    QtGui.QSizePolicy.Expanding)

    FigureCanvas.updateGeometry(self)

    self.setupSub(1)

 
    def setupSub(self, numSubRows, numSubCols = 1, sharex = False, sharey = 
False):

    self.fig.clf()

    for m in range(1,numSubRows+1):

    for n in range(1,numSubCols+1):

    axName = 'ax%s'%m

    axLoc = 100*numSubRows+10*n+m

    #print axLoc

    if sharex:

    if m>1:

    self.axDict[axName] = self.fig.add_subplot(axLoc, 
sharex = self.axDict['ax%s'%(m-1)])

    else:

    self.axDict[axName] = self.fig.add_subplot(axLoc)#, 
sharex = self.sharex, sharey = self.sharey)

    else:

    self.axDict[axName] = self.fig.add_subplot(axLoc)#, sharex 
= self.sharex, sharey = self.sharey)

 
    self.figInit = True

 
    self.fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9)

    self.xtitle=""

    self.ytitle=""

    #self.PlotTitle = "Plot"

    self.grid_status = True

    self.xaxis_style = 'linear'

    self.yaxis_style = 'linear'

    self.format_labels()

 
 
 
    def format_labels(self):

    if self.figInit:

    for ax in self.axDict.itervalues():

    ax.title.set_fontsize(10)

    ax.set_xlabel(self.xtitle, fontsize = 9)

    ax.set_ylabel(self.ytitle, fontsize = 9)

    labels_x = ax.get_xticklabels()

    labels_y = ax.get_yticklabels()

 
    for xlabel in labels_x:

    xlabel.set_fontsize(8)

    for ylabel in labels_y:

    ylabel.set_fontsize(8)

    ylabel.set_color('b')

    if ax.get_legend() != None:

    texts = ax.get_legend().get_texts()

    for text in texts:

    text.set_fontsize(8)

    else:

    print "please initiate the number of subplots. Call 
*.canvas.setupSub(numofSubs)"

 
    def sizeHint(self):

    w, h = self.get_width_height()

    return QtCore.QSize(w, h)

 
    def minimumSizeHint(self):

    return QtCore.QSize(10, 10)

 
    def sizeHint(self):

    w, h = self.get_width_height()

    return QtCore.QSize(w, h)

 
    def minimumSizeHint(self):

    return QtCore.QSize(10, 10)

 
 
class MyNavigationToolbar(NavigationToolbar) :

    def __init__(self , parent , canvas , direction = 'h' ) :

    #NavigationToolbar.__init__(self,parent,canvas)

    #self.layout = QVBoxLayout( self )

 
    self.canvas = canvas

    QWidget.__init__( self, parent )

 
    if direction=='h' :

    self.layout = QHBoxLayout( self )

    else :

    self.layout = QVBoxLayout( self )

 
    self.layout.setMargin( 2 )

    se

[Matplotlib-users] FourierDemo now on wxPyWiki

2009-01-16 Thread Tom Krauss
After some positive feedback and subsequent discussion on the  
wxPython users list, I decided to add a wiki page for the Fourier  
Demo I posted earlier:

   http://wiki.wxpython.org/MatplotlibFourierDemo

Robin, et. al., do you think this warrants moving up into a new  
category (e.g. RecipesMatplotlib) in the Recipes section?  I added it  
in the RecipesOther but there are so many recipes there that it seems  
kind of buried.

Best,
   Tom K.

--
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] FourierDemo now on wxPyWiki

2009-01-16 Thread John Hunter
On Fri, Jan 16, 2009 at 8:20 AM, Tom Krauss  wrote:
> After some positive feedback and subsequent discussion on the
> wxPython users list, I decided to add a wiki page for the Fourier
> Demo I posted earlier:
>
>   http://wiki.wxpython.org/MatplotlibFourierDemo
>
> Robin, et. al., do you think this warrants moving up into a new
> category (e.g. RecipesMatplotlib) in the Recipes section?  I added it
> in the RecipesOther but there are so many recipes there that it seems
> kind of buried.

Thanks for the reminder Tom -- the demo is indeed very nice but it
stuck in the back of my inbox.  I added it to mpl svn in
examples/user_interfaces/fourier_demo_wx.py

--
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] Figure with pyQt

2009-01-16 Thread projetmbc
That's great. I'm a real newbie with mpl and I would like to know how to 
change figure after a PyQt-Event.
That's must be simple but I don't see how to do this. My idea would be for 
example to show different kinds of draw like for example the sin function 
and another function. The users just have to click on some button. This is 
only to understand the way mpl manage changes in the figure.

If someone could helpme that would be greater than great.

Regards.
Christophe.




Message d'origine
>Date: Fri, 16 Jan 2009 07:00:07 -0800 (PST)
>De: B Clowers 
>Sujet: Re: [Matplotlib-users] Figure with pyQt
>A: matplotlib-users@lists.sourceforge.net, projet...@club-internet.fr
>
>
>You'll have to excuse some of the comments in the code (it's in a constant 
state of revision), but this is a basic PyQt4/matplotlib widget that I use 
quite often and can be embedded using QtDesigner as well.  You'll 
obviously need PyQt4, Matplotlib, and Numpy to run it.  Of course mods can 
be made as you see fit for your particular application.  
>
>I should note that Ctrl+Z zooms using the Spanselector and the top of the 
drawn span is the max Y and the the min Y always defaults to 0 (this works 
for my data sets).  Ctrl+A zooms out.  Save to csv is also an option 
(Ctrl+Alt+S)--this can fail if you've a weird data set. Ctrl+C copies a png of 
the current figure to the user's home directory (works for both Linux and 
Windows) and also puts the image on the current clipboard.  
>
>I've also added an option to make multiple plot layouts that are stored in 
a dictionary that can be accessed to plot to the given axes.  If anyone has 
a more elegant solution please share.  Let me know if you've questions.
>
>Cheers,
>
>Brian
>
>##
>#!/usr/bin/env python
>
> 
>import os
>
>import sys
>
> 
>from PyQt4 import QtCore,  QtGui
>
> 
>from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigureCanvas
>
>from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as 
NavigationToolbar
>
>#from matplotlib.backend_bases import NavigationToolbar2
>
> 
>from matplotlib.figure import Figure
>
> 
>from matplotlib.widgets import SpanSelector
>
>#from matplotlib.pyplot import savefig
>
> 
>import numpy as N
>
> 
> 
>class MyMplCanvas(FigureCanvas):
>
>    def __init__(self, parent=None, width = 5, height = 5, dpi = 100, 
sharex = None, sharey = None):
>
>    self.fig = Figure(figsize = (width, height), dpi=dpi, facecolor = 
'#FF')
>
>    self.axDict = {}
>
>    self.figInit = False
>
> 
>    self.sharey = sharey
>
>    self.sharey = sharey
>
> 
>#    self.ax1.hold(True)
>
> 
> 
>    FigureCanvas.__init__(self, self.fig)
>
>    #self.fc = FigureCanvas(self.fig)
>
>    FigureCanvas.setSizePolicy(self,
>
>    QtGui.QSizePolicy.Expanding,
>
>    QtGui.QSizePolicy.Expanding)
>
>    FigureCanvas.updateGeometry(self)
>
>    self.setupSub(1)
>
> 
>    def setupSub(self, numSubRows, numSubCols = 1, sharex = False, 
sharey = False):
>
>    self.fig.clf()
>
>    for m in range(1,numSubRows+1):
>
>    for n in range(1,numSubCols+1):
>
>    axName = 'ax%s'%m
>
>    axLoc = 100*numSubRows+10*n+m
>
>    #print axLoc
>
>    if sharex:
>
>    if m>1:
>
>    self.axDict[axName] = self.fig.add_subplot(axLoc, 
>sharex 
= self.axDict['ax%s'%(m-1)])
>
>    else:
>
>    self.axDict[axName] = self.fig.add_subplot(axLoc)#, 
sharex = self.sharex, sharey = self.sharey)
>
>    else:
>
>    self.axDict[axName] = self.fig.add_subplot(axLoc)#, sharex 
= self.sharex, sharey = self.sharey)
>
> 
>    self.figInit = True
>
> 
>    self.fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9)
>
>    self.xtitle=""
>
>    self.ytitle=""
>
>    #self.PlotTitle = "Plot"
>
>    self.grid_status = True
>
>    self.xaxis_style = 'linear'
>
>    self.yaxis_style = 'linear'
>
>    self.format_labels()
>
> 
> 
> 
>    def format_labels(self):
>
>    if self.figInit:
>
>    for ax in self.axDict.itervalues():
>
>    ax.title.set_fontsize(10)
>
>    ax.set_xlabel(self.xtitle, fontsize = 9)
>
>    ax.set_ylabel(self.ytitle, fontsize = 9)
>
>    labels_x = ax.get_xticklabels()
>
>    labels_y = ax.get_yticklabels()
>
> 
>    for xlabel in labels_x:
>
>    xlabel.set_fontsize(8)
>
>    for ylabel in labels_y:
>
>    ylabel.set_fontsize(8)
>
>    ylabel.set_color('b')
>
>    if ax.get_legend() != None:
>
>    texts = ax.get_legend().get_texts()
>
>    for text in texts:
>
>    text.set_fontsize(8)
>
>    else:
>
>    print "please initiate the number of subplots. Call

[Matplotlib-users] axes through origin (0,0)

2009-01-16 Thread Zoho Vignochi
Hello:

I would like to place the x label and y label to be placed above lines 
running through the origin (0,0). I am happy to leave the tick markings 
on the border around the plot.

I currently use a 
ax.axvline(x=0, color='black')
ax.axhline(y=0, color='black')

to get the lines, but how to get y label to be on the top of the vline 
that goes through x=0 and the xlabel to be at the left end of the hline 
that goes through y=0?

Thank you,

Zoho




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


[Matplotlib-users] Problem with shapelib

2009-01-16 Thread David Trethewey
I've had problems trying to read shapefiles using the matplotlib basemap 
toolkit

I can import the shapelib module without error but when I try to read a 
shapefile this happens:

Traceback (most recent call last):
  File "C:\Documents and Settings\David\Desktop\cornwall\try_4828.py", 
line 44, in 
read_4828()
  File "C:\Documents and Settings\David\Desktop\cornwall\try_4828.py", 
line 7, in read_4828
shp=shapelib.ShapeFile('4828/4828/package/shp/par1851.shp')
  File 
"c:\python25\lib\site-packages\basemap-0.99.1.0001-py2.5-win32.egg\shapelib\shapelib.py",
 
line 44, in __init__
self.this = apply(shapelibc.new_ShapeFile,args)
IOError: new_ShapeFile failed

Anyone know why this might be?

I'm using basemap 0.99.1 on Windows XP

David

--
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] Figure with pyQt

2009-01-16 Thread John Hunter
On Fri, Jan 16, 2009 at 9:40 AM,   wrote:
> That's great. I'm a real newbie with mpl and I would like to know how to
> change figure after a PyQt-Event.
> That's must be simple but I don't see how to do this. My idea would be for
> example to show different kinds of draw like for example the sin function
> and another function. The users just have to click on some button. This is
> only to understand the way mpl manage changes in the figure.
>
> If someone could helpme that would be greater than great.

Take a look at the matplotlib widgets example referenced below.  It
uses mpl widgets rather than qt widgets, but it should make clear the
logic of updating plot properties connected to callbacks

http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/examples/widgets/radio_buttons.py?content-type=text%2Fplain

--
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] Problem with shapelib

2009-01-16 Thread Jeff Whitaker
David Trethewey wrote:
> I've had problems trying to read shapefiles using the matplotlib basemap 
> toolkit
>
> I can import the shapelib module without error but when I try to read a 
> shapefile this happens:
>
> Traceback (most recent call last):
>   File "C:\Documents and Settings\David\Desktop\cornwall\try_4828.py", 
> line 44, in 
> read_4828()
>   File "C:\Documents and Settings\David\Desktop\cornwall\try_4828.py", 
> line 7, in read_4828
> shp=shapelib.ShapeFile('4828/4828/package/shp/par1851.shp')
>   File 
> "c:\python25\lib\site-packages\basemap-0.99.1.0001-py2.5-win32.egg\shapelib\shapelib.py",
>  
> line 44, in __init__
> self.this = apply(shapelibc.new_ShapeFile,args)
> IOError: new_ShapeFile failed
>
> Anyone know why this might be?
>
> I'm using basemap 0.99.1 on Windows XP
>
> David

David Can you post your shapefile somewhere so I can try it here?

-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


Re: [Matplotlib-users] axes through origin (0,0)

2009-01-16 Thread John Hunter
On Fri, Jan 16, 2009 at 9:47 AM, Zoho Vignochi  wrote:
> Hello:
>
> I would like to place the x label and y label to be placed above lines
> running through the origin (0,0). I am happy to leave the tick markings
> on the border around the plot.
>
> I currently use a
> ax.axvline(x=0, color='black')
> ax.axhline(y=0, color='black')
>
> to get the lines, but how to get y label to be on the top of the vline
> that goes through x=0 and the xlabel to be at the left end of the hline
> that goes through y=0?

Sadly, it is not possible, but it is on the wish list.  You can
however, turn it off, and then use ax.text to put text anywhere you
want.  Eg to place something at 0,0

  ax.text(0, 0, 'my xlabel')

--
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] Problem with shapelib

2009-01-16 Thread Jeff Whitaker
David Trethewey wrote:
> http://www.srcf.ucam.org/cukernow/par1851.shp
>
> It's a map of the historic parishes of England and Wales if you're 
> curious.
>
> David
>

David:  You also need the corresponding .shx and .dbf files to open it - 
perhaps that is the problem?

-Jeff
> Jeff Whitaker wrote:
>> David Trethewey wrote:
>>> I've had problems trying to read shapefiles using the matplotlib 
>>> basemap toolkit
>>>
>>> I can import the shapelib module without error but when I try to 
>>> read a shapefile this happens:
>>>
>>> Traceback (most recent call last):
>>>   File "C:\Documents and 
>>> Settings\David\Desktop\cornwall\try_4828.py", line 44, in 
>>> read_4828()
>>>   File "C:\Documents and 
>>> Settings\David\Desktop\cornwall\try_4828.py", line 7, in read_4828
>>> shp=shapelib.ShapeFile('4828/4828/package/shp/par1851.shp')
>>>   File 
>>> "c:\python25\lib\site-packages\basemap-0.99.1.0001-py2.5-win32.egg\shapelib\shapelib.py",
>>>  
>>> line 44, in __init__
>>> self.this = apply(shapelibc.new_ShapeFile,args)
>>> IOError: new_ShapeFile failed
>>>
>>> Anyone know why this might be?
>>>
>>> I'm using basemap 0.99.1 on Windows XP
>>>
>>> David
>>
>> David Can you post your shapefile somewhere so I can try it here?
>>
>> -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


[Matplotlib-users] cmap from sepparate color values

2009-01-16 Thread antonv

I have a series of 18 separate colors to create my cmap but I would like to
convert that to a continuous map which interpolates all the other values in
between my chosen colors. This should be really easy but I am not sure how
can it be solved. Any ideas?

Thanks,
Anton
-- 
View this message in context: 
http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21503197.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
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] cmap from sepparate color values

2009-01-16 Thread John Hunter
On Fri, Jan 16, 2009 at 10:33 AM, antonv  wrote:
>
> I have a series of 18 separate colors to create my cmap but I would like to
> convert that to a continuous map which interpolates all the other values in
> between my chosen colors. This should be really easy but I am not sure how
> can it be solved. Any ideas?

Although the logic of the LinearSegmentedColormap takes some time to
get your head around, it is pretty easy.

  
http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap


Here is an example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
colors = 'red', 'green', 'blue', 'yellow', 'orange'

ncolors = len(colors)

vals = np.linspace(0., 1., ncolors)

cdict = dict(red=[], green=[], blue=[])
for val, color in zip(vals, colors):
r,g,b = mcolors.colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))

cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)


x = np.arange(1.).reshape((100,100))

plt.imshow(x, cmap=cmap)

plt.show()

See also 
http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
 I just added a function to svn to support this, so with svn you can
do


colors = 'red', 'gray', 'green'
cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
X, Y = np.meshgrid(np.arange(10), np.arange(10))
plt.imshow(X+Y, cmap=cmap)

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


[Matplotlib-users] Basemap.pyproj: towgs84

2009-01-16 Thread Stephane Raynaud
Hi,

it seems that pyproj.Proj does not take into account the "towgs84" optional
parameter.
Here is what I simply tried:

from mpl_toolkits.basemap import *
lonref = -3.
latref = 47.

kwproj  = dict(proj="lcc",  a=6378249.2, b=6356515., x_0=60.,
y_0=20.,
lon_0="2d20'14.025", lat_0="46d48'",  lat_1="45d53'56.108",
lat_2="47d41'45.652")
print pyproj.Proj(**kwproj)(lonref, latref)

kwproj.update(towgs84="-168,-60,+320")
print pyproj.Proj(**kwproj)(lonref, latref)

Both transforms give the same result.

Try the same parameters with "cs2cs" changes the results as expected.
Did I miss something?

--
Stephane Raynaud
--
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] Basemap.pyproj: towgs84

2009-01-16 Thread Jeff Whitaker
Stephane Raynaud wrote:
> Hi,
>
> it seems that pyproj.Proj does not take into account the "towgs84" 
> optional parameter.
> Here is what I simply tried:
>
> from mpl_toolkits.basemap import *
> lonref = -3.
> latref = 47.
>
> kwproj  = dict(proj="lcc",  a=6378249.2, b=6356515., x_0=60.,  
> y_0=20.,
> lon_0="2d20'14.025", lat_0="46d48'",  lat_1="45d53'56.108", 
> lat_2="47d41'45.652")
> print pyproj.Proj(**kwproj)(lonref, latref)
>
> kwproj.update(towgs84="-168,-60,+320")
> print pyproj.Proj(**kwproj)(lonref, latref)
>
> Both transforms give the same result.
>
> Try the same parameters with "cs2cs" changes the results as expected.
> Did I miss something?
>
> --
> Stephane Raynaud

Stephanie:  All the arguments you pass to the Proj instance were used.  
I don't pretend to understand what's supposed to be happening here, but  
I guess you are mis-specifying or mis-interpreting some of the proj 
arguments.  The command-line version of proj gives the same answer:

 echo "-3.0 47.0" | proj +proj='lcc' +units=m +a=6378249.2 
+lon_0="2d20'14.025" +y_0=20.0 +b=6356515.0  +x_0=60.0 
+lat_2="47d41'45.652" +lat_1="45d53'56.108" +lat_0="46d48'"
194411.84   236007.03

echo "-3.0 47.0" | proj +proj='lcc' +units=m +a=6378249.2 
+lon_0="2d20'14.025" +y_0=20.0 +b=6356515.0 +x_0=60.0 
+lat_2="47d41'45.652" +lat_1="45d53'56.108" +lat_0="46d48'" 
+towgs84="-168,-60,+320"
194411.84   236007.03

-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


Re: [Matplotlib-users] Figure with pyQt

2009-01-16 Thread projetmbc
Title: Flashmail




Thanks a lot. That's a real good example.
 
Regards.
C.
 
>Take a look at the matplotlib widgets example referenced below. It >uses mpl widgets rather than qt widgets, but it should make clear the >logic of updating plot properties connected to callbacks > >http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/examples/widgets/radio_buttons.py?content-type=text%2Fplain


--
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-announce] Bug in image.py module ?

2009-01-16 Thread John Hunter
On Fri, Jan 16, 2009 at 3:12 PM,   wrote:
> Hello everybody,
>
> I may have found a bug in the module image.py, class AxesImage, of
> matplotlib 0.98.5.
>
> The method 'get_interpolation' has been defined twice. The first time
> it returns the attribute '_interpolation' (the right one). A few lines later,
> the second definition returns the attribute '_resample' (the wrong one ?).
>
> So, when you call 'get_interpolation' from an AxesImage instance such as
> 'imshow' it returns False instead of the proper interpolation scheme.
>
> What do you think ?

This is a bug, I'll fix it.  Thanks for the report.

Please do not post to matplotlib-announce.  You should post to
matplotlib-users instead.  matplotlib-announce is just for releases,
etc.

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


[Matplotlib-users] sizing plot right when embedded in wxPython

2009-01-16 Thread C M
Hi, this is somewhat of a wxPython issue, maybe, but in the
end I think my confusion is in how the sizing of a mpl canvas vs.
a figure ought to work, and so I am trying here first.

The attached code (a wxPython frame which displays a mpl
graph...what most here would call a plot) shows my problem.
The bottom of the graph is cut off unless I resize the frame to
be very tall.  But one can see that this is wrong because you
can resize it to make it not so tall, but then resize it again but
not let go (don't let it go idle, so it won't yet call it's size method)
and there is plenty of room for the x axis label and such.  When
you do let go it resizes it to cut off the bottom again.

I think this is because in the _SetSize method of the PlotPanel
class, it is getting the parent's client size, but this is not taking
into account two ways in which some of that size is used up
Maybe.  Like:

- In the case of a panel with other objects on it (like the two buttons),
it doesn't subtract the height of those buttons.

- In the case of a wx.AUINotebook, it doesn't subtract the height of
the bar where the tabs are.

I have played around with it but have wound up confusing myself,
and I am unclear as to how the _SetSize method is working here,
or if it is right for all circumstances (I guess it isn't, since my x

I have a nagging sense that I just should RTFM more, but on the
other hand I just wanted a reality check that the way I am thinking
about this is about on target.

Thanks,
Che


embed_problem.py
Description: application/python
--
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


[Matplotlib-users] Color themes

2009-01-16 Thread Yang Zhang
I'm no good at choosing colors.  Does matplotlib have a way to 
automatically assign colors (based on a theme), or provide a way to 
choose a color from a theme?  (Excel 2007 opened my eyes to this.) 
Currently, when I do:

   bar(..., color = 'r', ...)
   bar(..., color = 'y', ...)
   bar(..., color = 'b', ...)

I usually just choose one of the primary colors.  It would be nice if I 
could instead write the following (or better if the colors could be 
assigned automagically), so I needn't worry about choosing colors:

   bar(..., color = themecolor(0), ...)
   bar(..., color = themecolor(1), ...)
   bar(..., color = themecolor(2), ...)

I see these things called colormaps on the home page documentation, but 
I can't figure out how to use these (calling autumn() before plotting 
made no change to my plot) or whether they're even what I'm looking for. 
  Or perhaps there's some Python package out there completely unrelated 
to matplotlib that I could use?  Thanks in advance for any hints.
-- 
Yang Zhang
http://www.mit.edu/~y_z/

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


[Matplotlib-users] plot problem

2009-01-16 Thread Neal Becker
pylab.plot (xaxis, log10 (the_sum)*10)
where xaxis is numpy array, and log10(the_sum)*10 is my own class that is a 
valid python sequence (it is a c++ wrapper around boost::ublas), gives:
  File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
ret =  gca().plot(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
x86_64.egg/matplotlib/axes.py", line 3277, in plot
for line in self._get_lines(*args, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
for seg in self._plot_2_args(remaining, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
if is_string_like(tup2[1]):
  File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
try: obj + ''
RuntimeError: check:: failed

If I convert the 2nd arg to array, it works:
   pylab.plot (xaxis, np.array(log10 (the_sum)*10))

Doesn't plot support arbitrary sequences?



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

2009-01-16 Thread Eric Firing
Neal Becker wrote:
> pylab.plot (xaxis, log10 (the_sum)*10)
> where xaxis is numpy array, and log10(the_sum)*10 is my own class that is a 
> valid python sequence (it is a c++ wrapper around boost::ublas), gives:
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
> ret =  gca().plot(*args, **kwargs)
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 3277, in plot
> for line in self._get_lines(*args, **kwargs):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
> for seg in self._plot_2_args(remaining, **kwargs):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
> if is_string_like(tup2[1]):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
> try: obj + ''
> RuntimeError: check:: failed
> 
> If I convert the 2nd arg to array, it works:
>pylab.plot (xaxis, np.array(log10 (the_sum)*10))
> 
> Doesn't plot support arbitrary sequences?

Not *completely* arbitrary, evidently.  It has to raise a Python 
exception when an invalid operation (specifically, adding an empty 
string) is attempted.  Apparently your wrapper is not doing this.  This 
is the duck-typing check for a string that mpl has used from early times.

Eric

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

2009-01-16 Thread Neal Becker
On Friday 16 January 2009, Eric Firing wrote:
> Neal Becker wrote:
> > pylab.plot (xaxis, log10 (the_sum)*10)
> > where xaxis is numpy array, and log10(the_sum)*10 is my own class that is
> > a valid python sequence (it is a c++ wrapper around boost::ublas), gives:
> > File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
> > ret =  gca().plot(*args, **kwargs)
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 3277, in plot
> > for line in self._get_lines(*args, **kwargs):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
> > for seg in self._plot_2_args(remaining, **kwargs):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
> > if is_string_like(tup2[1]):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
> > try: obj + ''
> > RuntimeError: check:: failed
> >
> > If I convert the 2nd arg to array, it works:
> >pylab.plot (xaxis, np.array(log10 (the_sum)*10))
> >
> > Doesn't plot support arbitrary sequences?
>
> Not *completely* arbitrary, evidently.  It has to raise a Python
> exception when an invalid operation (specifically, adding an empty
> string) is attempted.  Apparently your wrapper is not doing this.  This
> is the duck-typing check for a string that mpl has used from early times.
>
> Eric
Is it possible that this could be better?  I'm not sure what's happening here, 
but I think it is trying to see if my type can be a string first.  It can, but 
that's not a good idea in this case.  It should correctly support a sequence 
(and iterator) protocol.  Shouldn't matplotlib try that first?


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

2009-01-16 Thread Neal Becker
On Friday 16 January 2009, Eric Firing wrote:
> Neal Becker wrote:
> > pylab.plot (xaxis, log10 (the_sum)*10)
> > where xaxis is numpy array, and log10(the_sum)*10 is my own class that is
> > a valid python sequence (it is a c++ wrapper around boost::ublas), gives:
> > File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
> > ret =  gca().plot(*args, **kwargs)
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 3277, in plot
> > for line in self._get_lines(*args, **kwargs):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
> > for seg in self._plot_2_args(remaining, **kwargs):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
> > if is_string_like(tup2[1]):
> >   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> > x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
> > try: obj + ''
> > RuntimeError: check:: failed
> >
> > If I convert the 2nd arg to array, it works:
> >pylab.plot (xaxis, np.array(log10 (the_sum)*10))
> >
> > Doesn't plot support arbitrary sequences?
>
> Partial correction to my previous post:
> is_string_like looks for a TypeError or ValueError to be raised. I
> suppose we could look for any exception, since your object raises a
> RuntimeError.
>
> I wonder whether it would be equally effective and more robust if the
> test were
>
> try: '' + obj
>
> instead of the other way around.
>
> Eric

IIRC, boost::python translates c++ exceptions to RuntimeError.  If true, then 
it's a lot easier to fix matplotlib than to fix boost::python wrappers.


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

2009-01-16 Thread Eric Firing
Neal Becker wrote:
> pylab.plot (xaxis, log10 (the_sum)*10)
> where xaxis is numpy array, and log10(the_sum)*10 is my own class that is a 
> valid python sequence (it is a c++ wrapper around boost::ublas), gives:
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
> ret =  gca().plot(*args, **kwargs)
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 3277, in plot
> for line in self._get_lines(*args, **kwargs):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
> for seg in self._plot_2_args(remaining, **kwargs):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
> if is_string_like(tup2[1]):
>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
> x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
> try: obj + ''
> RuntimeError: check:: failed
> 
> If I convert the 2nd arg to array, it works:
>pylab.plot (xaxis, np.array(log10 (the_sum)*10))
> 
> Doesn't plot support arbitrary sequences?

Partial correction to my previous post:
is_string_like looks for a TypeError or ValueError to be raised. I 
suppose we could look for any exception, since your object raises a 
RuntimeError.

I wonder whether it would be equally effective and more robust if the 
test were

try: '' + obj

instead of the other way around.

Eric

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

2009-01-16 Thread Eric Firing
Neal Becker wrote:
> On Friday 16 January 2009, Eric Firing wrote:
>> Neal Becker wrote:
>>> pylab.plot (xaxis, log10 (the_sum)*10)
>>> where xaxis is numpy array, and log10(the_sum)*10 is my own class that is
>>> a valid python sequence (it is a c++ wrapper around boost::ublas), gives:
>>> File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
>>> ret =  gca().plot(*args, **kwargs)
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 3277, in plot
>>> for line in self._get_lines(*args, **kwargs):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
>>> for seg in self._plot_2_args(remaining, **kwargs):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
>>> if is_string_like(tup2[1]):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
>>> try: obj + ''
>>> RuntimeError: check:: failed
>>>
>>> If I convert the 2nd arg to array, it works:
>>>pylab.plot (xaxis, np.array(log10 (the_sum)*10))
>>>
>>> Doesn't plot support arbitrary sequences?
>> Not *completely* arbitrary, evidently.  It has to raise a Python
>> exception when an invalid operation (specifically, adding an empty
>> string) is attempted.  Apparently your wrapper is not doing this.  This
>> is the duck-typing check for a string that mpl has used from early times.
>>
>> Eric
> Is it possible that this could be better?  I'm not sure what's happening 
> here, 
> but I think it is trying to see if my type can be a string first.  It can, 
> but 
> that's not a good idea in this case.  It should correctly support a sequence 
> (and iterator) protocol.  Shouldn't matplotlib try that first?
> 
No, it really needs to find out if it is a string, and a string is 
iterable, so a string-specific check is needed.

Eric

--
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] cmap from sepparate color values

2009-01-16 Thread antonv

Thanks for the quick reply John! Now it makes a lot more sense. The next dumb
question is what is SVN and where can I find more bout it?


John Hunter-4 wrote:
> 
> On Fri, Jan 16, 2009 at 10:33 AM, antonv 
> wrote:
>>
>> I have a series of 18 separate colors to create my cmap but I would like
>> to
>> convert that to a continuous map which interpolates all the other values
>> in
>> between my chosen colors. This should be really easy but I am not sure
>> how
>> can it be solved. Any ideas?
> 
> Although the logic of the LinearSegmentedColormap takes some time to
> get your head around, it is pretty easy.
> 
>  
> http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap
> 
> 
> Here is an example:
> 
> import numpy as np
> import matplotlib.pyplot as plt
> import matplotlib.colors as mcolors
> import matplotlib.cm as cm
> colors = 'red', 'green', 'blue', 'yellow', 'orange'
> 
> ncolors = len(colors)
> 
> vals = np.linspace(0., 1., ncolors)
> 
> cdict = dict(red=[], green=[], blue=[])
> for val, color in zip(vals, colors):
> r,g,b = mcolors.colorConverter.to_rgb(color)
> cdict['red'].append((val, r, r))
> cdict['green'].append((val, g, g))
> cdict['blue'].append((val, b, b))
> 
> cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)
> 
> 
> x = np.arange(1.).reshape((100,100))
> 
> plt.imshow(x, cmap=cmap)
> 
> plt.show()
> 
> See also
> http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
>  I just added a function to svn to support this, so with svn you can
> do
> 
> 
> colors = 'red', 'gray', 'green'
> cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
> X, Y = np.meshgrid(np.arange(10), np.arange(10))
> plt.imshow(X+Y, cmap=cmap)
> 
> 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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21512920.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


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

2009-01-16 Thread Eric Firing
Neal Becker wrote:
> On Friday 16 January 2009, Eric Firing wrote:
>> Neal Becker wrote:
>>> pylab.plot (xaxis, log10 (the_sum)*10)
>>> where xaxis is numpy array, and log10(the_sum)*10 is my own class that is
>>> a valid python sequence (it is a c++ wrapper around boost::ublas), gives:
>>> File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/pyplot.py", line 2096, in plot
>>> ret =  gca().plot(*args, **kwargs)
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 3277, in plot
>>> for line in self._get_lines(*args, **kwargs):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 394, in _grab_next_args
>>> for seg in self._plot_2_args(remaining, **kwargs):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/axes.py", line 267, in _plot_2_args
>>> if is_string_like(tup2[1]):
>>>   File "/usr/lib/python2.5/site-packages/matplotlib-0.98.5.2-py2.5-linux-
>>> x86_64.egg/matplotlib/cbook.py", line 277, in is_string_like
>>> try: obj + ''
>>> RuntimeError: check:: failed
>>>
>>> If I convert the 2nd arg to array, it works:
>>>pylab.plot (xaxis, np.array(log10 (the_sum)*10))
>>>
>>> Doesn't plot support arbitrary sequences?
>> Partial correction to my previous post:
>> is_string_like looks for a TypeError or ValueError to be raised. I
>> suppose we could look for any exception, since your object raises a
>> RuntimeError.
>>
>> I wonder whether it would be equally effective and more robust if the
>> test were
>>
>> try: '' + obj
>>
>> instead of the other way around.
>>
>> Eric
> 
> IIRC, boost::python translates c++ exceptions to RuntimeError.  If true, then 
> it's a lot easier to fix matplotlib than to fix boost::python wrappers.

After poking around a little, I conclude that there is nothing gained by 
having is_string_like look for particular exceptions, so I will relax 
that, which should solve your problem with no negative consequences for 
anything else.

I've committed the change to the 98.5 maintenance branch, but I'm having 
trouble with svnmerge, so I don't know how long it will take to get it 
into the trunk.

Eric

--
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] cmap from sepparate color values

2009-01-16 Thread Eric Firing
antonv wrote:
> Thanks for the quick reply John! Now it makes a lot more sense. The next dumb
> question is what is SVN and where can I find more bout it?

http://sourceforge.net/svn/?group_id=80706
http://subversion.tigris.org/

Eric

> 
> 
> John Hunter-4 wrote:
>> On Fri, Jan 16, 2009 at 10:33 AM, antonv 
>> wrote:
>>> I have a series of 18 separate colors to create my cmap but I would like
>>> to
>>> convert that to a continuous map which interpolates all the other values
>>> in
>>> between my chosen colors. This should be really easy but I am not sure
>>> how
>>> can it be solved. Any ideas?
>> Although the logic of the LinearSegmentedColormap takes some time to
>> get your head around, it is pretty easy.
>>
>>  
>> http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap
>>
>>
>> Here is an example:
>>
>> import numpy as np
>> import matplotlib.pyplot as plt
>> import matplotlib.colors as mcolors
>> import matplotlib.cm as cm
>> colors = 'red', 'green', 'blue', 'yellow', 'orange'
>>
>> ncolors = len(colors)
>>
>> vals = np.linspace(0., 1., ncolors)
>>
>> cdict = dict(red=[], green=[], blue=[])
>> for val, color in zip(vals, colors):
>> r,g,b = mcolors.colorConverter.to_rgb(color)
>> cdict['red'].append((val, r, r))
>> cdict['green'].append((val, g, g))
>> cdict['blue'].append((val, b, b))
>>
>> cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)
>>
>>
>> x = np.arange(1.).reshape((100,100))
>>
>> plt.imshow(x, cmap=cmap)
>>
>> plt.show()
>>
>> See also
>> http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
>>  I just added a function to svn to support this, so with svn you can
>> do
>>
>>
>> colors = 'red', 'gray', 'green'
>> cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
>> X, Y = np.meshgrid(np.arange(10), np.arange(10))
>> plt.imshow(X+Y, cmap=cmap)
>>
>> 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
>>
>>
> 


--
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] cmap from sepparate color values

2009-01-16 Thread antonv

Thanks again! That looks cool and seems that it can be used it to a lot of
other projects I have going on!

Anton


efiring wrote:
> 
> antonv wrote:
>> Thanks for the quick reply John! Now it makes a lot more sense. The next
>> dumb
>> question is what is SVN and where can I find more bout it?
> 
> http://sourceforge.net/svn/?group_id=80706
> http://subversion.tigris.org/
> 
> Eric
> 
>> 
>> 
>> John Hunter-4 wrote:
>>> On Fri, Jan 16, 2009 at 10:33 AM, antonv 
>>> wrote:
 I have a series of 18 separate colors to create my cmap but I would
 like
 to
 convert that to a continuous map which interpolates all the other
 values
 in
 between my chosen colors. This should be really easy but I am not sure
 how
 can it be solved. Any ideas?
>>> Although the logic of the LinearSegmentedColormap takes some time to
>>> get your head around, it is pretty easy.
>>>
>>>  
>>> http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap
>>>
>>>
>>> Here is an example:
>>>
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import matplotlib.colors as mcolors
>>> import matplotlib.cm as cm
>>> colors = 'red', 'green', 'blue', 'yellow', 'orange'
>>>
>>> ncolors = len(colors)
>>>
>>> vals = np.linspace(0., 1., ncolors)
>>>
>>> cdict = dict(red=[], green=[], blue=[])
>>> for val, color in zip(vals, colors):
>>> r,g,b = mcolors.colorConverter.to_rgb(color)
>>> cdict['red'].append((val, r, r))
>>> cdict['green'].append((val, g, g))
>>> cdict['blue'].append((val, b, b))
>>>
>>> cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)
>>>
>>>
>>> x = np.arange(1.).reshape((100,100))
>>>
>>> plt.imshow(x, cmap=cmap)
>>>
>>> plt.show()
>>>
>>> See also
>>> http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
>>>  I just added a function to svn to support this, so with svn you can
>>> do
>>>
>>>
>>> colors = 'red', 'gray', 'green'
>>> cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
>>> X, Y = np.meshgrid(np.arange(10), np.arange(10))
>>> plt.imshow(X+Y, cmap=cmap)
>>>
>>> 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
>>>
>>>
>> 
> 
> 
> --
> 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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21513073.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
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] cmap from sepparate color values

2009-01-16 Thread Eric Firing
antonv wrote:
> Thanks again! That looks cool and seems that it can be used it to a lot of
> other projects I have going on!

If you are looking for something to use for your own projects, I 
recommend not svn but one of the more modern distributed vcs systems: 
mercurial (hg), bzr, or git.  I use and like mercurial:

http://www.selenic.com/mercurial/wiki/

Eric

> 
> Anton
> 
> 
> efiring wrote:
>> antonv wrote:
>>> Thanks for the quick reply John! Now it makes a lot more sense. The next
>>> dumb
>>> question is what is SVN and where can I find more bout it?
>> http://sourceforge.net/svn/?group_id=80706
>> http://subversion.tigris.org/

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


[Matplotlib-users] NOAA .bull file parsing

2009-01-16 Thread antonv

Dear all,

I know this is not related to matplotlib but this seems to be the only place
where I found people that have knowledge of both NOAA data and python so
please bear with me.

The .bull file that NOAA gives for upload is an ascii file formatted for
human readability but it creates a lot of issues when I am trying to parse
it. Here is a link to one of these files:

ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/wave/prod/wave.20090117/bulls.t00z/akw.46001.bull

Do you have any idea on how to extract the data there in columns for
plotting with matplotlib? If you look at the file you'll notice that there
is both a header and a footer for the file that needs to be eliminated and
the main columns have sub columns also. Another issue is that in a column
there is missing data that should keep it's relationship with the time
column. And the last issue, some of the values there are preceded by a "*"
sign that should just be removed too.

Any ideas are greatly appreciated! 

Anton

-- 
View this message in context: 
http://www.nabble.com/NOAA-.bull-file-parsing-tp21513800p21513800.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


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