[Matplotlib-users] change tick label font size
I'm using matplotlib 0.9, is there a best way to do this: for labeltick in ax.xaxis.get_majorticklabels() + ax.yaxis.get_majorticklabels(): labeltick.set_fontsize(15) I can't do: ax.tick_params(labelsize=15) as here: http://matplotlib.sourceforge.net/api/axes_api.html?highlight=ticklabel_format#matplotlib.axes.Axes.tick_params is it a new feature? -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] How to find out the extend of the actual image in pixels
Hi, I would like to know how to find out the extend of the actual image in a plot, in units of pixels. As example I have attached a plot which is essentially empty. The lower left corner is indicated by a red dot - what pixel position does this location have? When opening this image in e.g. kview it is easy to find out that this left corner of the actual plot corresponds to pixel (100,540). And so the upper right corner (the yellow dot) is (720,60). But how do I find out these coordinates when generating such a plot with matplotlib? Are there some variables of the axis or the actual plot that contain these numbers? Thanks Alex attachment: mainplotTEST.png-- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
On Wed, Sep 29, 2010 at 4:44 AM, Alexander Dietz alexanderdie...@googlemail.com wrote: I would like to know how to find out the extend of the actual image in a plot, in units of pixels. As example I have attached a plot which is essentially empty. The lower left corner is indicated by a red dot - what pixel position does this location have? When opening this image in e.g. kview it is easy to find out that this left corner of the actual plot corresponds to pixel (100,540). And so the upper right corner (the yellow dot) is (720,60). But how do I find out these coordinates when generating such a plot with matplotlib? Are there some variables of the axis or the actual plot that contain these numbers? Take a look at the transformations tutorial. http://matplotlib.sourceforge.net/users/transforms_tutorial.html To convert from data - pixel coordinates, use the axes transData transformation In [1]: ax = gca() In [2]: ax.transData.transform((0.5, 0.5)) Out[2]: array([ 333.125, 245. ]) You can also use mpl events to inspect the coordinates of the point under the mouse In [3]: fig = gcf() In [4]: def on_click(event): ...: print event.x, event.y ...: ...: In [5]: cid = fig.canvas.mpl_connect('button_press_event', on_click) In [6]: 188 166.0 300 227.0 384 292.0 In [7]: fig.canvas.mpl_disconnect(cid) See http://matplotlib.sourceforge.net/users/event_handling.html for more info. JDH -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
Hi John, thanks for the reply, but I think your method is not working: On Wed, Sep 29, 2010 at 15:39, John Hunter jdh2...@gmail.com wrote: On Wed, Sep 29, 2010 at 4:44 AM, Alexander Dietz alexanderdie...@googlemail.com wrote: I would like to know how to find out the extend of the actual image in a plot, in units of pixels. As example I have attached a plot which is essentially empty. The lower left corner is indicated by a red dot - what pixel position does this location have? When opening this image in e.g. kview it is easy to find out that this left corner of the actual plot corresponds to pixel (100,540). And so the upper right corner (the yellow dot) is (720,60). But how do I find out these coordinates when generating such a plot with matplotlib? Are there some variables of the axis or the actual plot that contain these numbers? Take a look at the transformations tutorial. http://matplotlib.sourceforge.net/users/transforms_tutorial.html To convert from data - pixel coordinates, use the axes transData transformation In [1]: ax = gca() In [2]: ax.transData.transform((0.5, 0.5)) Out[2]: array([ 333.125, 245. ]) I have create a different plot (attached) and the point of the upper right corner (the yellow dot) is still at (720,60) as before. But with transData I get a completely wrong result: print ax.transData.transform((10.0, 20.0)) [ 576. 432.] Also the lower left points gets wrong coordinates. Maybe I am doing something stupidly wrong here? Thanks Alex You can also use mpl events to inspect the coordinates of the point under the mouse In [3]: fig = gcf() In [4]: def on_click(event): ...: print event.x, event.y ...: ...: In [5]: cid = fig.canvas.mpl_connect('button_press_event', on_click) In [6]: 188 166.0 300 227.0 384 292.0 In [7]: fig.canvas.mpl_disconnect(cid) See http://matplotlib.sourceforge.net/users/event_handling.html for more info. JDH attachment: mainplotTEST.png-- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz alexander.diet...@googlemail.com wrote: print ax.transData.transform((10.0, 20.0)) [ 576. 432.] Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left), not (upper,left). So this is saying that the yellow dot at 10,20 (data coords) is 576 pixels up from the bottom and 432 pixels over from the left. JDH -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
This is interesting. It seems that the event.x, event.y values are for the entire figure area rather than limited to the image. Anyone know how to get the image values instead? Also, I wonder how one might get the values of the pixels (i.e. image value) at the pixels that you click on. One more thing -- is there a way to make the cursor be a full plot window cross -- graphically like: -- || | || | || | ||-| || | || | -- It makes it easier to align with the axes sometimes (the IDL astronomy library has a routine called rdplot that does this). Jon -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] colorbar uncentered plots
On Tue, Sep 28, 2010 at 10:56 PM, Philip Vetter pv+matplot...@math.duke.edupv%2bmatplot...@math.duke.edu wrote: Hello! see below for sample code. (1) I find that the second subplot is shifted to the right. This seems to happen generally with colorbar. How do I fix it? (2) is there a way to clear/remove selected parts of the figure? I am using ipython for interactive figure drawing I find clf() will erase everything, cla() will empty the square plot, but I can't see how to clear the first subfigure or the colorbar. This would be useful as any changes to the colorbar create a new one. (uncomment the second cbar line to see this) (3) is it possible to modify the orientation of cbar once drawn? cbar.orientation ='horizontal' plt.draw() plt.show() leaves it unchanged. Thank you for your help! Here is my code: == #!/usr/bin/env python import matplotlib.pyplot as plt import numpy as np from time import sleep x = np.arange(0, 10, 0.2) y = np.sin(x) fig = plt.figure() ax1 = fig.add_subplot(211) cax1 = ax1.plot(x, y) ax2 = fig.add_subplot(212) A = np.random.random_integers(0, 10, 100).reshape(10, 10) cax2 = ax2.imshow(A, interpolation=nearest,vmin=-1,vmax=11 ) cbar = fig.colorbar(cax2) #cbar = fig.colorbar(cax2, ticks=[0, 5, 10]) plt.savefig('colorbartest.pdf') == -- Philip, Typically, when creating a colorbar, matplotlib steals some space from a particular axes. This is fine for single plots, but it looks atrocious when doing subplots. Instead, what you want is axes_grid1 http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/ (note, if you have a version earlier than 1.0.0, then it is called axes_grid and it is a little bit different) With this, you can specify a bunch of layout options ahead of time and get an object with all of the axes you need. In particular, I think you want to look at http://matplotlib.sourceforge.net/plot_directive/mpl_toolkits/axes_grid/examples/demo_axes_grid.py A quick note to clear up typical confusion in that demo... You can still use subplots and embed an AxesGrid within a subplot region (although, I find this unnecessary). For this reason, the linked demo has three subplots in a single figure, and each of those subplots have four subplots. Therefore, when creating each AxesGrid, one needs to specify the subplot coordinates such as 131, 132, 133, but you can simply use 111 if you want AxesGrid to handle all of your subplotting. To address one of your other questions, you can easily specify the orientation of your colorbar to be horizontal or vertical. I hope that helps! Ben Root -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] change tick label font size
On Wed, Sep 29, 2010 at 4:21 AM, Ruggero giurr...@gmail.com wrote: I'm using matplotlib 0.9, is there a best way to do this: for labeltick in ax.xaxis.get_majorticklabels() + ax.yaxis.get_majorticklabels(): labeltick.set_fontsize(15) I can't do: ax.tick_params(labelsize=15) as here: http://matplotlib.sourceforge.net/api/axes_api.html?highlight=ticklabel_format#matplotlib.axes.Axes.tick_params is it a new feature? Yes, this is a new feature for v1.0.0 because setting parameters for ticks have been so difficult and confusing in the past. The way you have it right now for version 0.9 is the correct way to do it for that version. Ben Root -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
Hi, On Wed, Sep 29, 2010 at 16:00, John Hunter jdh2...@gmail.com wrote: On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz alexander.diet...@googlemail.com wrote: print ax.transData.transform((10.0, 20.0)) [ 576. 432.] Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left), not (upper,left). So this is saying that the yellow dot at 10,20 (data coords) is 576 pixels up from the bottom and 432 pixels over from the left. ok maybe it is. But then I need the size of the entire figure written to a file. How can I find out the pixel-size of the entire figure, inclusive every title, axis, labels... Thanks Alex JDH -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Missing Toolbar Button inside Wx Application
Hi all, if I plot an normal figure the toolbar contains an button (looks like a checkbox), which can be used to edit the lines and axes parameters. But when I embed such a figure in an Wx application, this specfic button is missing. Is there a way around it? Thanks for your help, Sebi Parts of the Code: import wx import os import numpy as np import wx.grid import filtertools as ft # Matplotlib Figure object from matplotlib.figure import Figure # import the WxAgg FigureCanvas object, that binds Figure to # WxAgg backend -- a wxPanel from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas # import the NavigationToolbar WxAgg widget from matplotlib.backends.backend_wx import NavigationToolbar2Wx class MplPanel(wx.Panel): def __init__(self, *args, **kwds): wx.Panel.__init__(self, *args, **kwds) self.__set_properties() self.__do_layout() self.figure = Figure(figsize=(sizex, sizey), dpi=res) self.axes = self.figure.add_subplot(111) self.axes.set_xticks(np.arange(self.xmin_limit, self.xmax_limit, 20)) self.axes.set_yticks(np.arange(self.ymin, self.ymax, 0.1)); self.axes.axis([self.xmin,self.xmax,self.ymin,self.ymax]) self.axes.grid(True) self.axes.set_xlabel('Wavelength [nm]',fontsize=14) self.axes.set_ylabel('Transmission [%] or Intensity [a.u.]',fontsize=14) self.figure.subplots_adjust(left=0.07, bottom=0.09, right=0.97, top=0.94,wspace=0.20, hspace=0.20) self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) self.toolbar.Show() self.SetSizer(self.sizer) self.Fit() ... -- Dr. Sebastian Rhode Grünwalder Str. 103a 81547 München Tel: +49 89 4703091 Mobil: +49 15122810945 sebrh...@googlemail.com -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
If you're just looking for the dimensions of the overall figure in pixels, you can easily access them through other means. E.g: import matplotlib.pyplot as plt fig = plt.figure() _, _, width, height = fig.bbox.extents # - Extent of the figure in pixels fig.savefig('temp.png', dpi=fig.dpi) # - Be sure to specify the dpi!! Note that you'll have to specify that you want to save the figure at the same DPI it was when you called the extents... The figure will be saved with whatever default DPI is in your .matplotlibrc, which is commonly different than the default screen dpi (80). Hope that helps, -Joe On Wed, Sep 29, 2010 at 9:44 AM, Alexander Dietz alexanderdie...@googlemail.com wrote: Hi, On Wed, Sep 29, 2010 at 16:00, John Hunter jdh2...@gmail.com wrote: On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz alexander.diet...@googlemail.com wrote: print ax.transData.transform((10.0, 20.0)) [ 576. 432.] Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left), not (upper,left). So this is saying that the yellow dot at 10,20 (data coords) is 576 pixels up from the bottom and 432 pixels over from the left. ok maybe it is. But then I need the size of the entire figure written to a file. How can I find out the pixel-size of the entire figure, inclusive every title, axis, labels... Thanks Alex JDH -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Making room for tick labels
Not to pile on the auto-adjust to make labels fit bandwagon, but I've been following the FAQ on adjusting the subplot locations to make room for too-long tick labels: http://matplotlib.sourceforge.net/faq/howto_faq.html#automatically-make-room-for-tick-labels and have found that the FAQ code isn't very robust. For example, if I interactively change the size of the plotting window so the ylabels touch the left hand side of the window, stretching it right again pushes the labels and the subplots too far to the right (see attached 'auto_subplot_adjust.toofar.png'). If I make the window too narrow so the figure itself shrinks too much, it starts to raise 'ValueError: left cannot be = right' exceptions, and then really shrinks the plot even more (see attached 'auto_subplot_adjust.leftright.png'). Any suggestions for making this more robust? Justin attachment: auto_subplot_adjust.toofar.pngattachment: auto_subplot_adjust.leftright.png-- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] how to display figure from a GUI app?
I have a GTK app which runs its matplotlib stuff in a separate thread. If I call pylab.show() at the end of building the plot the first time it displays, then after that I have to destroy the window before it will think about plotting something else, and it never does (it pretends to - my log message tell me that it is). If I call pylab.draw() no window is ever displayed. My GUI is always active. I would like to pop up a new top-level window for each figure. How do I do that? My current build-a-plot code looks like this: figure = pylab.figure() ax = figure.add_subplot(111) ax.yaxis.set_major_formatter(pylab.FormatStrFormatter('%.7f')) ... build dates and prices lists ... ax.plot(dates, prices) formatter = matplotlib.dates.DateFormatter('%H:%M:%S') ax.xaxis.set_major_formatter(formatter) figure.autofmt_xdate() ... what goes here? ... Instead of show() or draw() as the last line what should I be doing? Thx, Skip Montanaro -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to display figure from a GUI app?
On Wed, Sep 29, 2010 at 3:43 PM, Skip Montanaro s...@pobox.com wrote: I have a GTK app which runs its matplotlib stuff in a separate thread. If I call pylab.show() at the end of building the plot the first time it displays, then after that I have to destroy the window before it will think about plotting something else, and it never does (it pretends to - my log message tell me that it is). If I call pylab.draw() no window is ever displayed. My GUI is always active. I would like to pop up a new top-level window for each figure. How do I do that? My current build-a-plot code looks like this: figure = pylab.figure() ax = figure.add_subplot(111) ax.yaxis.set_major_formatter(pylab.FormatStrFormatter('%.7f')) ... build dates and prices lists ... ax.plot(dates, prices) formatter = matplotlib.dates.DateFormatter('%H:%M:%S') ax.xaxis.set_major_formatter(formatter) figure.autofmt_xdate() ... what goes here? ... Instead of show() or draw() as the last line what should I be doing? Thx, Skip Montanaro Which version of matplotlib are you using? There have been numerous improvements to interactivity and multiple calls to show() in version 1.0 and beyond. There might still be some issues with multiple gui event loops that I think is currently being addressed by the ipython group. Maybe someone else here might be more knowledgeable about that. I hope that helps! Ben Root -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to find out the extend of the actual image in pixels
On Wed, Sep 29, 2010 at 11:12 PM, Jonathan Slavin jsla...@cfa.harvard.edu wrote: This is interesting. It seems that the event.x, event.y values are for the entire figure area rather than limited to the image. Anyone know how to get the image values instead? Typically, images in matplotlib are associated with data coordinate. And mouse events have xdata and ydata attributes. However, if you're using imshow with the extent keyword, you need one more step. Below is an example. arr = np.arange(10).reshape((2,5)) x1, x2, y1, y2 = [-1.5, 3.5, 2.5, 4.5] imshow(arr, extent=[x1, x2, y1, y2], origin=lower) from matplotlib.transforms import Bbox, BboxTransform bbox_in = Bbox.from_extents([x1, y1, x2, y2]) bbox_out = Bbox.from_bounds(-0.5, -0.5, arr.shape[1], arr.shape[0]) # transform from data coordinate into image coordinate. tr = BboxTransform(bbox_in, bbox_out) print tr.transform_point((-1, 3)) # pixel (0,0) of arr print tr.transform_point((3, 4)) # pixel (4,1) of arr Also, I wonder how one might get the values of the pixels (i.e. image value) at the pixels that you click on. One more thing -- is there a way to make the cursor be a full plot window cross -- graphically like: -- | | | | | | | | | ||-| | | | | | | -- It makes it easier to align with the axes sometimes (the IDL astronomy library has a routine called rdplot that does this). One option is to use widgets http://matplotlib.sourceforge.net/examples/widgets/cursor.html Regards, -JJ Jon -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users