[Matplotlib-users] help visualizing plots
dear list, can someone tell me why I don't see anything when I run this script? it is a modified version of the traits example... I expected to see three plots with one line each... from enthought.traits.api import HasTraits, Instance, Range, Array, on_trait_change, Property,cached_property, Bool from enthought.traits.ui.api import View, Item from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure from matplotlib.axes import Axes from matplotlib.lines import Line2D from enthought.traits.ui.api import CustomEditor import wx import numpy def MakePlot(parent, editor): fig = editor.object.figure panel = wx.Panel(parent, -1) canvas = FigureCanvasWxAgg(panel, -1, fig) toolbar = NavigationToolbar2Wx(canvas) toolbar.Realize() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(canvas,1,wx.EXPAND|wx.ALL,1) sizer.Add(toolbar,0,wx.EXPAND|wx.ALL,1) panel.SetSizer(sizer) canvas.SetMinSize((300,600)) return panel class PlotModel(HasTraits): figure = Instance(Figure, ()) axes1 = Instance(Axes) axes2 = Instance(Axes) axes3 = Instance(Axes) line1 = Instance(Line2D) line2 = Instance(Line2D) line3 = Instance(Line2D) _draw_pending = Bool(False) #a flag to throttle the redraw rate # a variable parameter x = Array(value=numpy.arange(1, 31)) x2 = Array(value=numpy.arange(1, 31)) x3 = Array(value=numpy.arange(1, 31)) # a dependent variable y = Array(value=numpy.arange(1, 31)) y2 = Array(value=numpy.arange(1, 31)) y3 = Array(value=numpy.arange(1, 31)) traits_view = View( Item('figure', editor=CustomEditor(MakePlot), resizable=True, show_label=False), resizable=False, width=400, height=750 ) def _axes1_default(self): return self.figure.add_subplot(311) def _axes2_default(self): return self.figure.add_subplot(312) def _axes3_default(self): return self.figure.add_subplot(313) def _line1_default(self): return self.axes1.plot(self.x, self.y)[0] def _line2_default(self): return self.axes2.plot(self.x2, self.y2)[0] def _line3_default(self): return self.axes3.plot(self.x3, self.y3)[0] def redraw(self): if self._draw_pending: return canvas = self.figure.canvas if canvas is None: return def _draw(): canvas.draw() self._draw_pending = False wx.CallLater(50, _draw).Start() self._draw_pending = True if __name__=="__main__": model = PlotModel() model.configure_traits(model.redraw()) thank you, simone -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Venn diagrams
Hi all, Is there any simple way in matplotlib, or in any other python library, to make a simple Venn diagram, I want to show three events and their intersections? I have tried googling for any hints but didn't find anything. Thanks for any help! Ian -- --- Ian Harry School of Physics & Astronomy Queens Buildings, The Parade Cardiff, CF24 3AA Email: ian.ha...@astro.cf.ac.uk Phone: (+44) 29 208 75120 Mobile: (+44) 7890 479090 --- -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] imshow extent & toolbar zoom??
Hi All: Thanks to Michael & Ryan, I got my imshow call displaying the correct data range on the x axis! However, when I now use a toolbar to zoom the image, I'm getting a divide by zero error (see traceback below) I'm using Python 2.5.2, wx 2.8.7.1, and Matplotlib 0.98.5.2 on win32. Thanks for your (hopefully) continued patience with these newbie questions! amb Here is the call to imshow that I modified: self.myImage = self.axes.imshow(self.image_data,aspect='auto',extent=[self.pageOffset,s elf.pageOffset+self.pageSizeSamps,self.numChans,1]) from: self.myImage = self.axes.imshow(self.image_data,aspect='auto') The old version zooms just fine with no error. This code is called in a menu event handler Here is how I created the figure & toolbar: # def SetupPlot(self): self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.data = np.zeros((self.numChans,self.pageSizeSamps)) self.myImage = self.axes.imshow(self.data,aspect='auto') self.sizer.Add(self.canvas,pos=(1,1)) self.add_toolbar() # def add_toolbar(self): self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # On Windows platform, default window size is incorrect, so set # toolbar width to figure width. tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() # By adding toolbar in sizer, we are able to put it at the bottom # of the frame - so appearance is closer to GTK version. # As noted above, doesn't work for Mac. self.toolbar.SetSize((fw, th)) self.sizer.Add(self.toolbar,pos=(2,1)) # update the axes menu on the toolbar self.toolbar.update() Here is the error Traceback: Traceback (most recent call last): File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_wx.py", line 1 225, in _onLeftButtonUp FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt) File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1198, i n button_release_event self.callbacks.process(s, event) File "C:\Python25\Lib\site-packages\matplotlib\cbook.py", line 155, in process func(*args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 2048, i n release_zoom self.draw() File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 2070, i n draw self.canvas.draw() File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_wxagg.py", lin e 60, in draw FigureCanvasAgg.draw(self) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 279, in draw self.figure.draw(self.renderer) File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 772, in draw for a in self.axes: a.draw(renderer) File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1545, in draw im.draw(renderer) File "C:\Python25\Lib\site-packages\matplotlib\image.py", line 233, in draw im = self.make_image(renderer.get_image_magnification()) File "C:\Python25\Lib\site-packages\matplotlib\image.py", line 220, in make_im age rx = widthDisplay / numcols ZeroDivisionError: float division From: matplotlib-users-boun...@lists.sourceforge.net [mailto:matplotlib-users-boun...@lists.sourceforge.net] On Behalf Of Lewis, Ambrose J. Sent: Saturday, February 14, 2009 7:07 AM To: matplotlib-users@lists.sourceforge.net Subject: [Matplotlib-users] x axis & imshow... Thanks Michael & Ryan! Worked great! amb -Original Message- From: Michael Droettboom [mailto:md...@stsci.edu] Sent: Fri 2/13/2009 1:14 PM To: Lewis, Ambrose J. Cc: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] x axis & imshow... You can pass "extent=(left, right, bottom, top)" to imshow to specify what the pixels in the array correspond to in data space. Mike Lewis, Ambrose J. wrote: > > Hi All: > > I'm working on a wxPython GUI that uses matplotlib. > > This program reads "chunks" of a data file into a numpy array and than > plots it using imshow. > > The first chunk works great. But, when I load chunks 2 to N, how can I > specify the different values for the labels on the x axis? > > I tried using "axes.set_xlim". This did reposition the x axis as > hoped, but the data is always being drawn back at the "zero" offset. > > Is there a way to tell the axis to map the array to a different x range? > > I can't read the whole file at once, it's just too big > > THANXS > > amb > > > > --
Re: [Matplotlib-users] how to make scatter plot and bar graphs in same figure?
Attached is a very simple example that shows how to do something similar to scatterhist in matplotlib Manuel per freem wrote: > hello, > > is there a way to make a 2d scatter plot that includes (outside the axes) > histograms of the marginals of the two variables? like the matlab function > 'scatterhist'. see this for an example: > > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/scatterhist.html > > ideally i'd like the histograms outside the scatter plot to also have axes > so that the height of each histogram bar will be interpretable. > i understand that there's no command for this - but how can i construct it? > i would not mind writing code to do this... if it's possible. right now > this is the only thing keeping me from switching from matlab to matplotlib > exclusively since i use these graphs a lot > > thank you > > > > > > -- > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > > > > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import NullFormatter x = np.random.randn(1000) y = np.random.randn(1000) nullfmt = NullFormatter() # no labels left, width = 0.1, 0.65 bottom, height = 0.1, 0.65 bottom_h = left_h = left+width+0.02 rect1 = [left, bottom, width, height] rect2 = [left, bottom_h, width, 0.2] rect3 = [left_h, bottom, 0.2, height] # start with a rectangular figure #fig = plt.Figure( (8,8) ) axScatter = plt.axes(rect1) axHistx = plt.axes(rect2)#, sharex=axScatter) axHisty = plt.axes(rect3)#, sharey=axScatter) axHistx.xaxis.set_major_formatter(nullfmt) axHisty.yaxis.set_major_formatter(nullfmt) axScatter.scatter(x,y) bins = np.linspace(-4,4,21) axHistx.hist(x, bins=bins) axHisty.hist(x, bins=bins, orientation='horizontal') axHistx.set_xlim( axScatter.get_xlim() ) axHisty.set_ylim( axScatter.get_ylim() ) plt.show() -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] updating colorbar to match new image data...
Hi All: I'm using the following code to create and display an image with a colorbar. Later on, I read data from a file and update the image. How do I refresh the colorbar to match this new data? Uncommenting the line in my "ReadFromFile" call below generates a new colorbar. I'd just like to replace the existing one to match the new data. I'm using Python 2.5.2, wx 2.8.7.1, and Matplotlib 0.98.5.2 on win32. THANXS amb # def SetupPlot(self): self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.data = np.zeros((self.numChans,self.pageSizeSamps)) self.myImage = self.axes.imshow(self.data,aspect='auto') self.cbar = self.figure.colorbar(self.myImage,ticks=[0,100],orientation='horizontal' ) self.sizer.Add(self.canvas,pos=(1,1),span=(1,2)) self.add_toolbar() # def ReadFromFile(self): if self.filename=="": print "pick a file first!" else: # bunch of code to read from file via numpy fromfile lives here... self.image_data = abs(fftshift(data,axes=[0])) self.myImage = self.axes.imshow(self.image_data,aspect='auto',extent=[self.pageOffset,s elf.pageOffset+self.pageSizeSamps,0,self.numChans]) #self.cbar = self.figure.colorbar(self.myImage,orientation='horizontal') self.canvas.draw() -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] updating colorbar to match new image data...
Lewis, Ambrose J. wrote: > Hi All: > > I’m using the following code to create and display an image with a > colorbar. Later on, I read data from a file and update the image. > > How do I refresh the colorbar to match this new data? For a colorbar cb I use: cb.set_clim(vmin=min_value,vmax=max_value) cb.draw_all() With this method you have to calculate the minimum and maximum values first. JLS -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to make scatter plot and bar graphs in same figure?
On Mon, Feb 16, 2009 at 7:22 AM, Manuel Metz wrote: > Attached is a very simple example that shows how to do something similar > to scatterhist in matplotlib > > That's a nice example. Are you going to check that into SVN? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Venn diagrams
Ian Harry wrote: > Hi all, > > Is there any simple way in matplotlib, or in any other python library, to > make a simple Venn diagram, I want to show three events and their > intersections? I have tried googling for any hints but didn't find anything. > > You can use Sage (http://www.sagemath.org or http://sagenb.org) http://wiki.sagemath.org/interact/misc#AnInteractiveVennDiagram (scroll down to see the picture; email me off-list if you'd like help in setting up an account or installing Sage; you can use Sage as a python library). Even if you don't use Sage and something like the interactive Venn diagram listed in the URL gives you relevant code for creating such a thing in matplotlib. Sage uses matplotlib in the background to actually draw the Venn diagram. Thanks, Jason -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] updating colorbar to match new image data...
Lewis, Ambrose J. wrote: > Hi All: > > I’m using the following code to create and display an image with a > colorbar. Later on, I read data from a file and update the image. > > How do I refresh the colorbar to match this new data? Uncommenting the > line in my “ReadFromFile” call below generates a new colorbar. I’d just > like to replace the existing one to match the new data. > > I’m using Python 2.5.2, wx 2.8.7.1, and Matplotlib 0.98.5.2 on win32. > > THANXS > > amb > > > > > # > > def SetupPlot(self): > > self.figure = Figure() > > self.axes = self.figure.add_subplot(111) > > self.canvas = FigureCanvas(self, -1, self.figure) > > self.data = np.zeros((self.numChans,self.pageSizeSamps)) > > self.myImage = self.axes.imshow(self.data,aspect='auto') > > self.cbar = > self.figure.colorbar(self.myImage,ticks=[0,100],orientation='horizontal') > > self.sizer.Add(self.canvas,pos=(1,1),span=(1,2)) > > self.add_toolbar() > > > > # > > def ReadFromFile(self): > > if self.filename=="": > > print "pick a file first!" > > else: > > # bunch of code to read from file via numpy fromfile lives here… > > self.image_data = abs(fftshift(data,axes=[0])) > > self.myImage = > self.axes.imshow(self.image_data,aspect='auto',extent=[self.pageOffset,self.pageOffset+self.pageSizeSamps,0,self.numChans]) > > #self.cbar = > self.figure.colorbar(self.myImage,orientation='horizontal') > > self.canvas.draw() The problem is that you are generating a new mappable, so the old colorbar is disconnected from the new image. I haven't tested with an example, but it looks like you should be able to replace the calls in ReadFromFile to imshow with method calls on the original image object. Try using self.myImage.set_data, self.myImage.set_extent, and self.myImage.changed. The latter will tell the colorbar to update itself. Eric -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] matplotlib on remote host Mac OS/X
Hi, I'm trying to rum python and matlpotlib on a remote mac host from my mac laptop. Both have Mac OS/X 10.5.6 and I'm using ssh -Y ... However, the graphic window does not appear and, when I run p.show() everything gets stuck. Any insight? Thanks -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] matplotlib on remote host Mac OS/X
Davide Lazzati wrote: > Hi, > > I'm trying to rum python and matlpotlib on a remote mac host from my > mac laptop. Both have Mac OS/X 10.5.6 and I'm using ssh -Y ... > > However, the graphic window does not appear and, when I run p.show() > everything gets stuck. > > Any insight? > > Thanks > Davide: This will only work if you use an X11-based backend (like GTK Agg), since only X11 is forwarded over SSH. If you're using a mac-native backend, the window is popping up on your mac's screen when you do show(). -Jeff -- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users