[Matplotlib-users] dynamically share axes
Hi Everyone, I have several subplots in one figure, and I'm trying to dynamically display different subplots depending on user input. Everything works fine with the set_visible command, except that I'm running into a problem with shared axes. Basically, I'd like to be able to choose to display subplots (211) and (212) with optionally shared x-axes, and it looks like I either need to find a way to tell add_subplot to not delete overlapping axes *or* to be able to dynamically set axes to share an x-axis My first thought was to create two sets of overlapping axes and set one pair invisible, something like this: f = figure(0) ax1_noshare = f.add_subplot(211) ax2_noshare = f.add_subplot(212) ax1_share = f.add_subplot(211) ax2_share = f.add_subplot(212, sharex=ax1_share) # more code here if show_shared: ax1_noshare.set_visible(False) ax1_noshare.set_visible(False) ax1_share.set_visible(True) ax1_share.set_visible(True) #etc However, the second set of add_subplot(211) calls (to create ax1_share and ax2_share) delete the overlapping axes defined just above, so when I go to set the non-shared axes visible, I get a blank figure. I could, of course, change my code such that I can just optionally set ax2 to share ax1's x-axis, but I'd need a function like: ax2.set_shared_axis(sharex=ax1) which doesn't appear to exist. So my question is, Is it possible to either specify that add_subplot should not delete overlapping axes, or to set a shared axis after the axis has already been created? Thanks, Michael -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Asymmetrical arrangements of subplots
2011/5/5 Sebastian Krieger sebastian.krie...@usp.br: Dear all, I have a small question about subplot. I want to avoid creating plot axes manually using pylab.axes, to create an asymmetrical arrangement of subplots like the following code in Matlab: figure subplot(2,2,1:2) text(.5,.5,'subplot(2,2,1:2)',... 'FontSize',14,'HorizontalAlignment','center') subplot(2,2,3) text(.5,.5,'subplot(2,2,3)',... 'FontSize',14,'HorizontalAlignment','center') subplot(2,2,4) text(.5,.5,'subplot(2,2,4)',... 'FontSize',14,'HorizontalAlignment','center') Reference: http://www.mathworks.com/help/techdoc/ref/subplot.html Is it possible in matplotlib? Easier done than explained: import matplotlib.pyplot as plt plt.subplot(121) plt.subplot(222) plt.subplot(224) plt.show() Goyo -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] mplot3d and plot_surface: How to 'hide' objects inside the surface
Hi, I have the following situation. I have been following the example to create a 3d surface, as explained here: http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo2.html and I have altered the code slightly to plot a straight red line from the center outside of the sphere (see code at the end of this email). As one can see, the whole line is visible always, no matter how the sphere is turned. Is there a way to 'hide' those parts of the red line, which are 'behind' the blue surface? Like you stick a pencil into an apple and turn the apple, so you can see parts of the pencil, depending on how the apple is rotated (except the part of the pencil inside the apple)? If someone can help me with that problem that would be great. Thanks Alex from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() #ax = fig.add_subplot(111, projection='3d') ax = Axes3D(fig) u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot([0,15],[0.0,0.0],'r', lw=4) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') plt.show() -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Subplot x-tick labels overlap with each other and with titles
Hi Whenever I create figures with at least 3x3 subplots, the x-tick labels overlap with each other and they also overlap with the title of the adjacent subplot, rendering the entire figure illegible. I know that I can fine-tune the plot to look exactly the way I want with wspace and hspace for instance, but I don't understand why this is the default behavior. I wonder if I have a system font issue, such that matplotlib thinks the fonts are smaller than they really are. My questions: 1) Is this the intended behavior of matplotlib, or is there something wrong with my installation? 2) Assuming I don't have an installation issue, is there a very general parameter I can change so that the overlap doesn't occur, rather than manually adjusting every figure? Minimal code to reproduce the problem: import numpy as np import matplotlib.pyplot as plt plt.figure() plt.subplot(331) plt.subplot(334) plt.plot(np.arange(1)) plt.title('Title') plt.show() I'm attaching the output figure, although I'm not sure if the list accepts attachments. The x-tick labels on subplot 334 overlap each other, and the title of subplot 334 overlaps with the x-tick labels in subplot 331. System: Ubuntu 10.04 x64 All packages are the stable versions from Synaptic, including ipython, python, numpy, matplotlib 0.99.1.1 I've also tried the Enthought distribution with matplotlib 1.0.1 and the results are the same I've tried both Wx and Tk backends and the results are the same I've tried `matplotlib.rcParams['xtick.labelsize'] = 'x-small'`, and this does make the labels smaller, but for sufficiently large numbers the overlap still occurs. Thanks for any help! Chris attachment: output.png-- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Subplot x-tick labels overlap with each other and with titles
2011/5/5 Chris Rodgers chris.rodg...@berkeley.edu: 1) Is this the intended behavior of matplotlib, or is there something wrong with my installation? This is by design, hspace and vspace are proportional to the size of each subplot. Also the number of ticks does not depend on the subplot or labels size (using the default locator). So you have to fine tune if things don't fit together. Of course you can write custom subplot-like functions which take care of this the way you find more convenient. I wonder how other plotting packages deal with this. Goyo -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mplot3d and plot_surface: How to 'hide' objects inside the surface
On Thursday, May 5, 2011, Alexander Dietz alexanderdie...@googlemail.com wrote: Hi, I have the following situation. I have been following the example to create a 3d surface, as explained here: http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo2.html and I have altered the code slightly to plot a straight red line from the center outside of the sphere (see code at the end of this email). As one can see, the whole line is visible always, no matter how the sphere is turned. Is there a way to 'hide' those parts of the red line, which are 'behind' the blue surface? Like you stick a pencil into an apple and turn the apple, so you can see parts of the pencil, depending on how the apple is rotated (except the part of the pencil inside the apple)? If someone can help me with that problem that would be great. Thanks Alex from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() #ax = fig.add_subplot(111, projection='3d') ax = Axes3D(fig) u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot([0,15],[0.0,0.0],'r', lw=4) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') plt.show() Mplot3d is not a true 3d plotting system. I would recommend mayavi for that. Because mplot3d is a hack to render 3d objects with a 2d rendering system, matplotlib can't get the the layering right. Maybe in the far future this will be changed, but for now, it is a design limitation. Ben -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Asymmetrical arrangements of subplots
2011/5/4 Sebastian Krieger sebastian.krie...@usp.br Dear all, I have a small question about subplot. I want to avoid creating plot axes manually using pylab.axes, to create an asymmetrical arrangement of subplots like the following code in Matlab: figure subplot(2,2,1:2) text(.5,.5,'subplot(2,2,1:2)',... 'FontSize',14,'HorizontalAlignment','center') subplot(2,2,3) text(.5,.5,'subplot(2,2,3)',... 'FontSize',14,'HorizontalAlignment','center') subplot(2,2,4) text(.5,.5,'subplot(2,2,4)',... 'FontSize',14,'HorizontalAlignment','center') Reference: http://www.mathworks.com/help/techdoc/ref/subplot.html Is it possible in matplotlib? Cheers, Sebastian Sebastian, mpl 1.0.0 came with a powerful gridspec tool for more advanced handling of subplots. Maybe this will be of use to you? http://matplotlib.sourceforge.net/users/gridspec.html?highlight=gridspec Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] removing lines from plot
On Wed, May 4, 2011 at 11:23 PM, butt...@gmail.com wrote: redlines.set_visible(False) it is also possible to delete the line from ax.lines. Ex: del ax.lines[-1] deletes the last line. you need to perform a redraw for the change to be visible on the plot. There are more correct ways to do this. For example, each artist object comes with a remove method: http://matplotlib.sourceforge.net/api/artist_api.html?highlight=remove#matplotlib.artist.Artist.remove So, if you save the lines that you create from the call to plot, you can subsequently remove them at your leisure. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Animating plots with the Qt backend
On Tue, May 3, 2011 at 3:57 AM, Gerald Storer g...@mrxtech.com.au wrote: Hello, I've been trying to animate some plots with the qt backend and run into a couple of problems. Firstly, I'd like to be able to update the axis limits in an automated fashion as the data changes size. Secondly, Resizing figures appears to redraw everything _but_ items with the animation flag. The is causing me problems when the animation is paused or the frames are occurring slow enough such that there is a noticable period where the my lines disappear. I've sort of solved both of these problems but the solutions seem hackish. In particular updating the axis limits is slowing the animation by 25% and toggling the animated field using the qt events just feels like its asking for trouble. Below is the qt animation example with my solutions. Adjust the size of the plot after the animation finishes to see the effect of the resize hack. I would be grateful if anyone could suggest some improvements. Thanks, Gerald. # For detailed comments on animation and the techniqes used here, see # the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations import os import sys #import matplotlib #matplotlib.use('Qt4Agg') from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from PyQt4 import QtCore, QtGui ITERS = 100 import numpy as np import time class BlitQT(FigureCanvas): def __init__(self): FigureCanvas.__init__(self, Figure()) self.ax = self.figure.add_subplot(111) #self.ax.grid() self.draw() self.old_size = self.ax.bbox.width, self.ax.bbox.height self.ax_background = self.copy_from_bbox(self.ax.bbox) self.cnt = 0 self.x = np.arange(0,2*np.pi,0.01) self.sin_line, = self.ax.plot(self.x, np.sin(self.x), animated=True) self.cos_line, = self.ax.plot(self.x, np.cos(self.x), animated=True) self.draw() self.old_limits = self.ax.get_xlim(),self.ax.get_ylim() self.tstart = time.time() self.maintimer = self.startTimer(10) ## HACK for disapearing objects on resize def resizeEvent(self,evt): super(BlitQT,self).resizeEvent(evt) self.sin_line.set_animated(False) def paintEvent(self,evt): super(BlitQT,self).paintEvent(evt) self.sin_line.set_animated(True) def timerEvent(self, evt): current_size = self.ax.bbox.width, self.ax.bbox.height if self.old_size != current_size: self.old_size = current_size #self.ax.clear() #self.ax.grid() self.draw() self.ax_background = self.copy_from_bbox(self.ax.bbox) self.restore_region(self.ax_background) # update the data self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0)*self.cnt/100.0) self.cos_line.set_ydata(np.cos(self.x+self.cnt/10.0)*self.cnt/100.0) ## HACK for updating axis limits self.ax.relim() self.ax.autoscale_view() current_limits = self.ax.get_xlim(),self.ax.get_ylim() if self.old_limits != current_limits: self.old_limits = current_limits self.draw() self.ax_background = self.copy_from_bbox(self.ax.bbox) self.blit(self.figure.bbox) # just draw the animated artist self.ax.draw_artist(self.sin_line) self.ax.draw_artist(self.cos_line) # just redraw the axes rectangle self.blit(self.ax.bbox) if self.cnt == 0: # TODO: this shouldn't be necessary, but if it is excluded the # canvas outside the axes is not initially painted. self.draw() if self.cnt==ITERS: # print the timing info and quit print 'FPS:' , ITERS/(time.time()-self.tstart) #sys.exit() self.killTimer(self.maintimer) else: self.cnt += 1 app = QtGui.QApplication(sys.argv) widget = BlitQT() widget.show() sys.exit(app.exec_()) Gerald, I haven't looked at your code, but I would like to point out that if you wish to experiment a little further with animations in matplotlib, there is a animation module that is in the current development branch (but has not been officially released). Maybe using it might help make your code less hack-ish? We would also greatly welcome any and all comments on the module before the next release of matplotlib. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution.
Re: [Matplotlib-users] Roll and offset around viewpoint with Axes3D
As for the roll issue described below : how hard would it be to implement something similar to tr = Affine2D().scale(2, 1).rotate_deg(30) inside mplot3D ? Where should I start ? All I want basically is define my viewpoint with 6 parameters (elev, azim, distance, roll, pitch and yaw), and not just 2 (elev,azim). I know it can be done interactively, but I want(need) to script it. Any suggestions ? Fréd On Sun, May 1, 2011 8:26 pm, Frederic Vogt wrote: Hello, I am using the scatter function and axes3D. I can define my viewpoint on my data points using the elev and azim parameters. But I am looking for more specification of the viewpoint : namely, I want to roll (i.e. rotate around the view axis) and offset it (i.e. get sideways, not rotate around my data points). Is there any way to do it ? At the moment, I am using transformation matrices applied to my data points to reproduce the roll and offset. Ultimately, I want to rotate and offset both the data points and axis, but the transformation matrices only impact the data point. Hence my question : any way to roll and offset around a viewpoint with Axes3D ? I don't want to do this interactively, I want to be able to program it. Thanks, and cheers ! Fréd -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] fill with a semilogy axis?
On Tue, May 3, 2011 at 3:40 AM, K.-Michael Aye kmichael@gmail.comwrote: A colleague posed an interesting challenge: How to do a filled plot having the y-axis in logarithm? I think I can do it with creating patches myself an adding it to the axis, but isn't there anything built-in? Best regards, Michael Does fill_between() not work for you? Note, I have never tried it on a log scale plot. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] UserWarning: Attempting to set identical bottom==top
On Sun, May 1, 2011 at 4:35 PM, C M cmpyt...@gmail.com wrote: I get this error and would like to know what to do to eliminate it and also what it means: C:\Python25\lib\site-packages\matplotlib\axes.py:2571: UserWarning: Attempting to set identical bottom==top results in singular transformations; automatically expanding. bottom=0, top=0 + 'bottom=%s, top=%s') % (bottom, top)) This is with Matplotlib 1.0.0. Thank you, Che I have seen this happen when the plot is set to use the limits of the data to guide the axes limits, but the data being displayed is either vertical or horizontal. It isn't a huge issue as the code is automatically padding the axes to make take the plot out of flat world. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] [Repost: Note suggested patches] In mplot3d, how is format_zdata supposed to work? Why is sensible_format_data called?
[Repost from 21 Mar 2011: note suggested patches] Hi all, I am using Matplotlib 1.0.1 and am seeing weird behaviour with mplot3d and ticker formatters, and I think I need to submit a patch to axes3d, but am not sure how much it will break, because format_zdata() and format_coord() look to be defined inconsistently. When trying to rotate a plot, which was created including the following commands, ... ax.plot(x[0,alow:atop],x[1,alow:atop],x[2,alow:atop],c=rgb.tolist()) ax.w_xaxis.set_major_locator(tic.LinearLocator(3)) ax.w_xaxis.set_major_formatter(tic.FormatStrFormatter('')) ax.w_yaxis.set_major_locator(tic.LinearLocator(3)) ax.w_yaxis.set_major_formatter(tic.FormatStrFormatter('')) ax.w_zaxis.set_major_locator(tic.LinearLocator(3)) ax.w_zaxis.set_major_formatter(tic.FormatStrFormatter('')) plt.draw() ... I received the following backtrace and error message: /usr/lib64/python2.6/site-packages/matplotlib/backend_bases.pyc in mouse_move(self, event) 2393 if event.inaxes and event.inaxes.get_navigate(): 2394 - 2395 try: s = event.inaxes.format_coord(event.xdata, event.ydata) 2396 except ValueError: pass 2397 except OverflowError: pass /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in format_coord(self, xd, yd) 474 475 xs = self.format_xdata(x) -- 476 ys = self.format_ydata(y) 477 zs = self.format_ydata(z) 478 return 'x=%s, y=%s, z=%s' % (xs, ys, zs) /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in format_ydata(self, y) 424 except TypeError: 425 fmt = self.w_yaxis.get_major_formatter() -- 426 return sensible_format_data(fmt, y) 427 428 def format_zdata(self, z): /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in sensible_format_data(self, value) 26 if abs(value) 1e4 or abs(value)1e-3: 27 s = '%1.4e' % value --- 28 return self._formatSciNotation(s) 29 else: 30 return '%4.3f' % value AttributeError: FormatStrFormatter instance has no attribute '_formatSciNotation' --- I am using FormatStrFormatter('') to try to obtain an empty tick. [1] It looks like sensible_format_data() assumes that self is class ScalarFormatter(Formatter), since this is the only ticker Formatter that has attribute _formatSciNotation(s). As far as I can tell, this means that sensible_format_data(fmt,y) should *only* be called if fmt has class ScalarFormatter(Formatter). [2] In axes3d.py, I see: def format_zdata(self, z): Return z string formatted. This function will use the attribute self.fmt_zdata if it is callable, else will fall back on the yaxis major formatter try: return self.fmt_zdata(z) except (AttributeError, TypeError): fmt = self.w_zaxis.get_major_formatter() return sensible_format_data(fmt, z) To me, it looks like the call to sensible_format_data(fmt, z) is wrong. The same error occurs in format_xdata() and format_ydata(). So I would like to submit a patch for format_xdata(), format_ydata(), format_zdata(), e.g.: def format_zdata(self, z): Return z string formatted. This function will use the attribute self.fmt_zdata if it is callable, else will fall back on the zaxis major formatter try: return self.fmt_zdata(z) except (AttributeError, TypeError): fmt = self.w_zaxis.get_major_formatter() try: return sensible_format_data(fmt, z) except (AttributeError, TypeError): return format_data(fmt, z) [3] But I am also worried about the comment else will fall back on the yaxis major formatter. Shouldn't this say the zaxis major formatter, since that is what the code does? Or should the code use the yaxis major formatter, since that is what the documentation says? The documentation http://matplotlib.github.com/mpl_toolkits/mplot3d/api.html agrees with the comment and not with the code. [4] In def format_coord(self, xd, yd), I see xs = self.format_xdata(x) ys = self.format_ydata(y) zs = self.format_ydata(z) Why doesn't the last line say zs = self.format_zdata(z) ? Best, Paul -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Matplotlib trims off the figure plotted
On Fri, Apr 29, 2011 at 7:18 AM, Musa Gabere musa.a...@gmail.com wrote: Hi Everyone, I am currently using matplotlib version 0.99 Ubuntu operating system. I am plotting a figure whose script is as follows. The figure i get is usually trimmed off. See the attached figure. Is there a way to solve this problem? Thanks import numpy as np import matplotlib.pyplot as plt conf_arr = [[33,2,0,0,0,0,0,0,0,1,3], [3,31,0,0,0,0,0,0,0,0,0], [0,4,41,0,0,0,0,0,0,0,1], [0,1,0,30,0,6,0,0,0,0,1], [0,0,0,0,38,10,0,0,0,0,0], [0,0,0,3,1,39,0,0,0,0,4], [0,2,2,0,4,1,31,0,0,0,2], [0,1,0,0,0,0,0,36,0,2,0], [0,0,0,0,0,0,1,5,37,5,1], [3,0,0,0,0,0,0,0,0,39,0], [0,0,0,0,0,0,0,0,0,0,38]] norm_conf = [] for i in conf_arr: a = 0 tmp_arr = [] a = sum(i, 0) for j in i: tmp_arr.append(float(j)/float(a)) norm_conf.append(tmp_arr) fig = plt.figure() plt.clf() ax = fig.add_subplot(111) ax.set_aspect(1) res = ax.imshow(np.array(norm_conf), cmap=plt.cm.jet, interpolation='nearest') width = len(conf_arr) height = len(conf_arr[0]) for x in xrange(width): for y in xrange(height): ax.annotate(str(conf_arr[x][y]), xy=(x, y), horizontalalignment='center', verticalalignment='center') cb = fig.colorbar(res) alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' plt.xticks(range(width), alphabet[:width]) plt.yticks(range(height), alphabet[:height]) plt.savefig('confusion_matrix.png', format='png') Musa, I just tested your code with the latest in the development branch, and it appears that whatever bug caused your problem has since been fixed. I don't know when the fix was made, but hopefully it made it into the v1.0.1 release. Cheers, Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Search for a row with a pattern in a column
On Thu, Apr 28, 2011 at 1:13 PM, Pau vim.u...@googlemail.com wrote: Hi, I am trying to grep in 650 data files a row which has a particular number on column 2, namely 0.250E+00 . Alternatively, I could look for that row by searching for the first column, which is 1 . Unfortunately, this row changes position in the 650 files and looks like this: --- . . . 4224 0.24993684469E-04 0.450621747970581E+01 -0.217168951034546E+01 0.798277109861374E-01 -0.598546504974365E+00 -0.947211563587189E+00 0.298483103513718E+00 0.694457411766052E+00 -0.135573709011078E+01 0.500285959243774E+01 0 4225 0.24993684469E-04 0.503941202163696E+01 -0.236623978614807E+01 -0.171467363834381E+00 -0.204598993062973E+00 -0.764434099197388E+00 0.354671090841293E+00 0.141895398497581E+00 -0.693929433822632E+00 0.556993389129639E+01 0 4226 0.24993684469E-04 0.403050041198730E+01 -0.215032029151917E+01 0.877652913331985E-01 -0.991083562374115E+00 0.611193120479584E+00 0.273028463125229E+00 0.364663577079773E+01 -0.221709823608398E+01 0.456908226013184E+01 0 1 0.250E+00 0.417827463150024E+01 -0.208329892158508E+01 0.104015089571476E+00 0.154748081695288E-02 -0.619542039930820E-02 -0.361486850306392E-02 0.216096282005310E+01 -0.701378881931305E+00 0.467000341415405E+01 0 4228 0.24993684469E-04 -0.348412361145020E+02 -0.309311046600342E+02 -0.551393890380859E+01 -0.908447951078415E-01 -0.427876152098179E-01 -0.533953774720430E-02 0.295748591423035E+01 -0.196792855858803E-01 0.469153327941895E+02 0 4229 0.24993684469E-04 0.427954912185669E+01 -0.195016658306122E+01 0.785302296280861E-01 0.806781768798828E+00 -0.110497450828552E+01 -0.624167263507843E+00 0.235030865669250E+01 -0.216405773162842E+01 0.470360040664673E+01 0 4230 0.24993684469E-04 0.551125669479370E+01 -0.394835329055786E+01 0.588055849075317E+00 -0.504932820796967E+00 0.104279957711697E+00 -0.213553920388222E+00 0.198102459311485E+00 -0.341262459754944E+00 0.680509042739868E+01 0 . . . - The purpose is to identify the row and then plot the 3rd and 4th columns once that row has been identified: X_inst = FILE[:, 2] # Column 3 Y_inst = FILE[:, 3] # Column 4 My problem is how to define those thanks a lot, Pau This is more of a numpy problem than a matplotlib problem. I would suggest asking on numpy's mailing list. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Saving figure for later editing
On Tue, Apr 26, 2011 at 3:02 PM, Eric Firing efir...@hawaii.edu wrote: On 04/26/2011 09:36 AM, butt...@gmail.com wrote: I believe this feature, which has been requested a number of times, but is still missing from matplotlib is genuinely useful for interactive plotting. Moreover, I've heard matlab has it... Here's a potential solution to cover my simple plotting needs. The goal is not to support all the weird and wonderful matplotlib features, if you need those you probably work only from script anyway. My approach is based on figureoptions.py in matplotlib.backends.qt4_editor (or the more recent version in spyder): 1) Save figure file: . get xy data for each plot object . get object styles (color of plots, linestyle, etc.) . save to auto-generated python script Later... 2) Open figure file: The script will open a new figure, recreate all objects and then apply styles to each object. You have full control over the figure and its contents again for editing Using this approach backwards compatibility should not be a issue (as demonstrated by figureoptions). On the other hand not all matplotlib objects/options will be supported. Any comments or suggestions ? Implementing anything like this will immediately lead to a stream of complaints that it doesn't support all the weird and wonderful matplotlib features. The vector backends are actually doing something like this, but saving in their respective graphics languages instead of in python. Presumably some sort of matplotlib_script backend could be written, using the pdf or svg backend as a template. Better practice is to use something like the ipython logging facility to save one's interactive commands, and then manually to edit that down to a script that creates the desired figure. That way one retains full control, reproducibility, and documentation of what went into a figure. Eric Not meaning to resurrect a dead thread, but I would like to point out that Matlab's functionality appears to have been implemented by saving figure components in a .mat file (but called them .fig instead). I have not investigated this any further, but I would wonder just how far-fetched it would be to be able to pickle the artist objects into our own sort of .fig files that we could load up on our own? Just food for thought... Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Customizing 3d plots
I apologize for the delay. I have not been paying attention to this mailing list for the past couple of months. My responses are below. On Wed, Apr 20, 2011 at 12:20 AM, José Alexandre Nalon na...@terra.com.brwrote: Greetings, I'm trying to use Matplotlib to plot 3d surfaces, with good results. While the plot are nice, there is little information on the website about customizing them. To get what I want, I used some tricks and hacks, and I am pretty sure that there are better ways to do it. Here is what I did, if you have any advice on how to do it better. * The wireframe lines in the surface are thicker than I wanted. I couldn't find a way to configure their thickness. To get thinner lines, I made my plots huge (about 24 inches), and adjusted fonts accordingly. This is a very ugly (and unpredictable) hack. That sounds like a decent feature request. Could you please file one at either sourceforge or github? * I need gray images, so I used the gray colormap. This, however, gave me very dark and bright areas, and I wanted a little less variation. Since my functions always range from 0. to 1., I set vmin=-1 and vmax=2. I got the result I wanted, but I feel that there is a better way to do that. This is more of an issue regarding colormap norms. You might want to read up on them here: http://matplotlib.sourceforge.net/api/colors_api.html?highlight=colormap%20norm#matplotlib.colors.Normalize * The grids on the 'walls' and 'floor', on the other hand, are very bright, and I wanted them darker. Couldn't find a way to do that. Not currently. These are hard-coded. I am hoping to have that and other things configurable in the next release of mpl. * In some plots, I don't want ticks on some axis. Setting ticks to [] gave me no result, and there is no method for that in the z-axis. Setting ticklabels to [] also made no difference. Is there a way to remove the ticks or the labels in 3d plots? Are you talking about the ticks, or the labels for the tick locations? Note that in 2d plots you can have ticks without labels, or labels without ticks. Currently in mplot3d, this is not very neat, and it is one thing I want to have cleaned up for the next release. I figure out that there is probably ways to do all those by handling the corresponding Artists, or other object of the kind. But they are full of details, and I don't know exactly where to start. Any directions will be appreciated. I've been using matplotlib for years, and it is always helpful, and the plots are always beautiful. Thanks for the nice work. Thanks for using matplotlib! Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] minvalue must be less than or equal to maxvalue error
On Mon, Apr 18, 2011 at 4:25 AM, Muffles dantares...@gmail.com wrote: Hello all, i created some program to read from netcdf files and plot the data, and it seems to work ok. But when i try to run an older file, it just shows this: Traceback (most recent call last): File netcdf2png.py, line 199, in module savefig(range.png) File /usr/lib/pymodules/python2.6/matplotlib/pyplot.py, line 356, in savefig return fig.savefig(*args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/figure.py, line 1032, in savefig self.canvas.print_figure(*args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/backend_bases.py, line 1476, in print_figure **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py, line 358, in print_png FigureCanvasAgg.draw(self) File /usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py, line 314, in draw self.figure.draw(self.renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/figure.py, line 773, in draw for a in self.axes: a.draw(renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/axes.py, line 1735, in draw a.draw(renderer) File /usr/lib/pymodules/python2.6/matplotlib/collections.py, line 704, in draw return Collection.draw(self, renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/collections.py, line 201, in draw self.update_scalarmappable() File /usr/lib/pymodules/python2.6/matplotlib/collections.py, line 477, in update_scalarmappable self._facecolors = self.to_rgba(self._A, self._alpha) File /usr/lib/pymodules/python2.6/matplotlib/cm.py, line 166, in to_rgba x = self.norm(x) File /usr/lib/pymodules/python2.6/matplotlib/colors.py, line 825, in __call__ raise ValueError(minvalue must be less than or equal to maxvalue) ValueError: minvalue must be less than or equal to maxvalue Any ideas? Thx in advance My best guess is that there is something messing up the colormap normalization. Without knowing more about your program and the data being plotted, I can't say more. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mplot3d and ticks
On Sat, Apr 16, 2011 at 8:17 AM, Giovanni Luca Ciampaglia junkie.dolp...@gmail.com wrote: Is there a way to control the distance between the axis label and the tick labels with mplot3d.Axes3D? For small figure sizes they overlap and I haven't found a way to fix that. My last resort was to remove the tick labels but that sucks for publication-quality plots. Cheers, -- Giovanni Luca Ciampaglia Giovanni, Sorry for the delay in responding. I have not been following this mailing list for the past couple of months. Currently, the distance for the positioning of the label and the ticks is hard-coded. Note that in the current development branch (and I believe in v1.0.1), I have made some significant fixes to the calculation and alignment of the tick labels. This has lead to substantial improvement (in my opinion) of the ticklabel placement. My plan is for the next release to remove many of the hard-coded values that governs the appearance of mplot3d plots. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] No Display in Axes3D with Logarithmic axes
2011/4/3 hongleij hongl...@126.com OS :Win7 SP1 ActivePython-2.7.1.3-win32-x86.msi numpy-1.5.1-win32-superpack-python2.7.exe matplotlib-1.0.1.win32-py2.7.exe Code: from mpl_toolkits.mplot3d import axes3d ax = axes3d.Axes3D(plt.gcf()) #ax.set_xlim(1,10) #ax.set_ylim(1,10) ax.set_xlabel(Download(GB)) ax.set_ylabel(Upload(GB)) ax.set_title(User Up/Down In 6 days) ax.set_xscale('log') # Error: Cause No display #ax.set_yscale('log') # group = ax.scatter3D([1,20,300],[1,20,300],[1,20,300]) #ax.legend( user_level_groups, [ user[0] for user in user_level_str_list] ) plt.show() Error: Exception in Tkinter callback Traceback (most recent call last): File C:\Python27\lib\lib-tk\Tkinter.py, line 1410, in __call__ return self.func(*args) File C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py, line 245, in resize self.show() File C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py, line 248, in draw FigureCanvasAgg.draw(self) File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 394, in draw self.figure.draw(self.renderer) File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File C:\Python27\lib\site-packages\matplotlib\figure.py, line 798, in draw func(*args) File C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py, line 172, in draw ax.draw(renderer) File C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axis3d.py, line 238, in draw self.label.draw(renderer) File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File C:\Python27\lib\site-packages\matplotlib\text.py, line 591, in draw ismath=ismath) File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 154, in draw_text self._renderer.draw_text_image(font.get_image(), int(x), int(y) + 1, angle, gc) File C:\Python27\lib\site-packages\numpy\ma\core.py, line 3818, in __int__ raise MaskError, 'Cannot convert masked element to a Python int.' MaskError: Cannot convert masked element to a Python int. Sorry for the delay in responding. Yes, this is a known bug. I have not been able to figure out its exact cause. At this point, I will just say that mplot3d does not support log scales. Sorry I could not be more helpful. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Animating plots with the Qt backend
Ah, I did not know that. I shall investigate. Thanks, Gerald. On 6/05/2011 7:27 AM, Benjamin Root wrote: On Tue, May 3, 2011 at 3:57 AM, Gerald Storer g...@mrxtech.com.au mailto:g...@mrxtech.com.au wrote: Hello, I've been trying to animate some plots with the qt backend and run into a couple of problems. Firstly, I'd like to be able to update the axis limits in an automated fashion as the data changes size. Secondly, Resizing figures appears to redraw everything _but_ items with the animation flag. The is causing me problems when the animation is paused or the frames are occurring slow enough such that there is a noticable period where the my lines disappear. I've sort of solved both of these problems but the solutions seem hackish. In particular updating the axis limits is slowing the animation by 25% and toggling the animated field using the qt events just feels like its asking for trouble. Below is the qt animation example with my solutions. Adjust the size of the plot after the animation finishes to see the effect of the resize hack. I would be grateful if anyone could suggest some improvements. Thanks, Gerald. # For detailed comments on animation and the techniqes used here, see # the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations import os import sys #import matplotlib #matplotlib.use('Qt4Agg') from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from PyQt4 import QtCore, QtGui ITERS = 100 import numpy as np import time class BlitQT(FigureCanvas): def __init__(self): FigureCanvas.__init__(self, Figure()) self.ax http://self.ax = self.figure.add_subplot(111) #self.ax.grid() self.draw() self.old_size = self.ax.bbox.width, self.ax.bbox.height self.ax_background = self.copy_from_bbox(self.ax.bbox) self.cnt = 0 self.x = np.arange(0,2*np.pi,0.01) self.sin_line, = self.ax.plot(self.x, np.sin(self.x), animated=True) self.cos_line, = self.ax.plot(self.x, np.cos(self.x), animated=True) self.draw() self.old_limits = self.ax.get_xlim(),self.ax.get_ylim() self.tstart = time.time() self.maintimer = self.startTimer(10) ## HACK for disapearing objects on resize def resizeEvent(self,evt): super(BlitQT,self).resizeEvent(evt) self.sin_line.set_animated(False) def paintEvent(self,evt): super(BlitQT,self).paintEvent(evt) self.sin_line.set_animated(True) def timerEvent(self, evt): current_size = self.ax.bbox.width, self.ax.bbox.height if self.old_size != current_size: self.old_size = current_size #self.ax.clear() #self.ax.grid() self.draw() self.ax_background = self.copy_from_bbox(self.ax.bbox) self.restore_region(self.ax_background) # update the data self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0)*self.cnt/100.0) self.cos_line.set_ydata(np.cos(self.x+self.cnt/10.0)*self.cnt/100.0) ## HACK for updating axis limits self.ax.relim() self.ax.autoscale_view() current_limits = self.ax.get_xlim(),self.ax.get_ylim() if self.old_limits != current_limits: self.old_limits = current_limits self.draw() self.ax_background = self.copy_from_bbox(self.ax.bbox) self.blit(self.figure.bbox) # just draw the animated artist self.ax.draw_artist(self.sin_line) self.ax.draw_artist(self.cos_line) # just redraw the axes rectangle self.blit(self.ax.bbox) if self.cnt == 0: # TODO: this shouldn't be necessary, but if it is excluded the # canvas outside the axes is not initially painted. self.draw() if self.cnt==ITERS: # print the timing info and quit print 'FPS:' , ITERS/(time.time()-self.tstart) #sys.exit() self.killTimer(self.maintimer) else: self.cnt += 1 app = QtGui.QApplication(sys.argv) widget = BlitQT() widget.show() sys.exit(app.exec_()) Gerald, I haven't looked at your code, but I would like to point out that if you wish to experiment a little further with animations in matplotlib, there is a animation module that is in the current development branch (but has not been officially released). Maybe using it might help make your code
Re: [Matplotlib-users] draw_event does not fire for savefig() when installing from source
On Thu, Apr 7, 2011 at 10:41 AM, Jeroen DR voetsjoeba+mplus...@gmail.comwrote: Hi, I'm using the method described on http://matplotlib.sourceforge.net/faq/howto_faq.html#howto-auto-adjust to automatically adjust my subplot figures to make room for my axis labels. I'm not drawing my graphs to the screen, but I'm instead outputting them to PNG files using a savefig(filename.png, dpi=100) call. I'm on a Ubuntu 9.04 Jaunty Jackalope system, so I originally used the python-matplotlib package for convenience, which contains matplotlib 0.98.5.2. However, I later also needed the option to move my legend on top of my figure, which means that I had to upgrade to at least matplotlib 0.99.x since I would need the bbox_to_anchor kwarg for that. Naturally nothing higher than 0.98 is available for Ubuntu 9.04, so I went and installed MPL from source. That worked, until I discovered that now the draw_event no longer fires when I call savefig(). It still fires for show(), but for some reason, after installing from source, it no longer does. I made sure that I installed all of MPL's dependencies; the build report lists version numbers for all them where it didn't before, so I'm pretty sure those are all satisfied. Here's the test program I used, adapted directly from the sample code. I also tried adding in manual fig.canvas.draw() calls to try and trigger the event manually, which seemingly are all happily ignored. import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10)) ax.set_yticks((2,5,7)) labels = ax.set_yticklabels(('really, really, really', 'long', 'labels')) def on_draw(event): print on_draw bboxes = [] for label in labels: bbox = label.get_window_extent() # the figure transform goes from relative coords-pixels and we # want the inverse of that bboxi = bbox.inverse_transformed(fig.transFigure) bboxes.append(bboxi) # this is the bbox that bounds all the bboxes, again in relative # figure coords bbox = mtransforms.Bbox.union(bboxes) if fig.subplotpars.left bbox.width: # we need to move it over fig.subplots_adjust(left=1.1*bbox.width) # pad a little fig.canvas.draw() return False fig.canvas.mpl_connect('draw_event', on_draw) #plt.show()# this fires draw_event plt.savefig('delete_me.png', dpi=100) # this doesn't Convinced this was a bug, I then tried compiling a whole bunch of different versions from source to see what version it stopped working at. It didn't work for any of them, including the 0.98.5.x builds. Finally, I tried grabbing python-matplotlib's matplotlibrc file and using it to override the compiled version's RC file with, and lo: draw_event fires again. I'm not very familiar with MPL's internals so I'm sure there's a reason for this (one thing I immediately noticed was that the DEB RC file seems to use the TkAgg backend, whereas the compiled version uses the GTKAgg backend). However, it feels to me like whether or not a user-mode event fires or not should not depend on some configuration settings. I've yet to figure out which setting exactly causes draw_event to fail, but I just wanted to let you guys know; might be a good idea to tweak the default settings so that draw_event behaves as expected. Cheers, Jeroen DR I wonder if this is backend-dependent. Which backend are you using for the installs from source? Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] matplotlib subplot is slow
On Thu, Mar 31, 2011 at 7:42 PM, Eddie Schlafly schla...@hotmail.comwrote: Hi all, I was surprised today to notice that subplot was the slowest part of some plotting code of mine. On my machine, the last line of the following code puts ten subplots on a figure and records the amount of time it took to make them: import matplotlib matplotlib.use('AGG') import time from matplotlib.pyplot import * def f(): ... t = time.time() ... clf() ... for i in xrange(10): ... subplot(5,2,i+1) ... return time.time()-t ... times = [f() for x in xrange(10)] This code gives me a bunch of times that are on average about half a second. I expected it to be much faster as I wasn't actually plotting anything. Is this expected? Can I choose a faster backend or something? I've experimented a little but without success. I realize that 5 hundredths of a second per subplot isn't terrifically slow, ... but I guess I make a lot of plots. Thanks a lot, Eddie Schlafly Eddie, Calling pyplot.subplot() may be slow because it has to determine which figure is the currently active figure, and then create a new axes object for that figure. I would suspect that passing in the figure object and calling add_subplot from the figure may speed things up. Also note that v1.0.0 introduced pyplot.subplots() which will create a figure, and an array of subplots all at once. There is also the gridspec method that might also be of interest. I hope that helps! Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Save or pickle pyplot object
On Tue, Mar 29, 2011 at 8:35 AM, Andreas Reisinger andreas.reisin...@tuwien.ac.at wrote: Hi! I would like to save a pyplot object as it is, including axes, lines, text, etc. into a file. When opening it again, I want to be able to add additional axes, lines and so on. Unfortunately pickle does not handle the pyplot object and gives me an error. Anyone knows a solution? All the best Aki This has been an often requested feature, but much harder to implement than expected. There is currently no known solution to this problem, but I certainly would hope that it becomes possible. Sorry I could not be of more help. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] UserWarning: Attempting to set identical bottom==top
On Thu, May 5, 2011 at 10:03 PM, C M cmpyt...@gmail.com wrote: On Thu, May 5, 2011 at 7:58 PM, Benjamin Root ben.r...@ou.edu wrote: On Sun, May 1, 2011 at 4:35 PM, C M cmpyt...@gmail.com wrote: I get this error and would like to know what to do to eliminate it and also what it means: C:\Python25\lib\site-packages\matplotlib\axes.py:2571: UserWarning: Attempting to set identical bottom==top results in singular transformations; automatically expanding. bottom=0, top=0 + 'bottom=%s, top=%s') % (bottom, top)) This is with Matplotlib 1.0.0. Thank you, Che I have seen this happen when the plot is set to use the limits of the data to guide the axes limits, but the data being displayed is either vertical or horizontal. What do you mean by the data being vertical or horizontal? I can get this error with a single point that is plotted on a time vs. values plot. It isn't a huge issue as the code is automatically padding the axes to make take the plot out of flat world. The problem is, when I use a py2exe'd app this error occurs and the user sees a message to see the log file for the error. I don't want that at all. It's a bad user experience. Is there a way I can prevent this error from ever being generated? Thanks. -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] [Repost: Note suggested patches] In mplot3d, how is format_zdata supposed to work? Why is sensible_format_data called?
On Thu, May 5, 2011 at 7:16 PM, Paul Leopardi paul.leopa...@iinet.net.auwrote: [Repost from 21 Mar 2011: note suggested patches] Hi all, I am using Matplotlib 1.0.1 and am seeing weird behaviour with mplot3d and ticker formatters, and I think I need to submit a patch to axes3d, but am not sure how much it will break, because format_zdata() and format_coord() look to be defined inconsistently. When trying to rotate a plot, which was created including the following commands, ... ax.plot(x[0,alow:atop],x[1,alow:atop],x[2,alow:atop],c=rgb.tolist()) ax.w_xaxis.set_major_locator(tic.LinearLocator(3)) ax.w_xaxis.set_major_formatter(tic.FormatStrFormatter('')) ax.w_yaxis.set_major_locator(tic.LinearLocator(3)) ax.w_yaxis.set_major_formatter(tic.FormatStrFormatter('')) ax.w_zaxis.set_major_locator(tic.LinearLocator(3)) ax.w_zaxis.set_major_formatter(tic.FormatStrFormatter('')) plt.draw() ... I received the following backtrace and error message: /usr/lib64/python2.6/site-packages/matplotlib/backend_bases.pyc in mouse_move(self, event) 2393 if event.inaxes and event.inaxes.get_navigate(): 2394 - 2395 try: s = event.inaxes.format_coord(event.xdata, event.ydata) 2396 except ValueError: pass 2397 except OverflowError: pass /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in format_coord(self, xd, yd) 474 475 xs = self.format_xdata(x) -- 476 ys = self.format_ydata(y) 477 zs = self.format_ydata(z) 478 return 'x=%s, y=%s, z=%s' % (xs, ys, zs) /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in format_ydata(self, y) 424 except TypeError: 425 fmt = self.w_yaxis.get_major_formatter() -- 426 return sensible_format_data(fmt, y) 427 428 def format_zdata(self, z): /usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in sensible_format_data(self, value) 26 if abs(value) 1e4 or abs(value)1e-3: 27 s = '%1.4e' % value --- 28 return self._formatSciNotation(s) 29 else: 30 return '%4.3f' % value AttributeError: FormatStrFormatter instance has no attribute '_formatSciNotation' --- I am using FormatStrFormatter('') to try to obtain an empty tick. [1] It looks like sensible_format_data() assumes that self is class ScalarFormatter(Formatter), since this is the only ticker Formatter that has attribute _formatSciNotation(s). As far as I can tell, this means that sensible_format_data(fmt,y) should *only* be called if fmt has class ScalarFormatter(Formatter). [2] In axes3d.py, I see: def format_zdata(self, z): Return z string formatted. This function will use the attribute self.fmt_zdata if it is callable, else will fall back on the yaxis major formatter try: return self.fmt_zdata(z) except (AttributeError, TypeError): fmt = self.w_zaxis.get_major_formatter() return sensible_format_data(fmt, z) To me, it looks like the call to sensible_format_data(fmt, z) is wrong. The same error occurs in format_xdata() and format_ydata(). So I would like to submit a patch for format_xdata(), format_ydata(), format_zdata(), e.g.: def format_zdata(self, z): Return z string formatted. This function will use the attribute self.fmt_zdata if it is callable, else will fall back on the zaxis major formatter try: return self.fmt_zdata(z) except (AttributeError, TypeError): fmt = self.w_zaxis.get_major_formatter() try: return sensible_format_data(fmt, z) except (AttributeError, TypeError): return format_data(fmt, z) [3] But I am also worried about the comment else will fall back on the yaxis major formatter. Shouldn't this say the zaxis major formatter, since that is what the code does? Or should the code use the yaxis major formatter, since that is what the documentation says? The documentation http://matplotlib.github.com/mpl_toolkits/mplot3d/api.html agrees with the comment and not with the code. [4] In def format_coord(self, xd, yd), I see xs = self.format_xdata(x) ys = self.format_ydata(y) zs = self.format_ydata(z) Why doesn't the last line say zs = self.format_zdata(z) ? Best, Paul Paul, This is a perfect example of the with many eyes, all bugs are shallow saying. I have been running into problems with this with respect to getting log scales to work. While your fixes doesn't completely address the issue, it does bring me a few steps closer. Your hunches are correct. There have been plenty of copy-n-paste mistakes within mplot3d, and it makes no sense to fall back onto the y-axis formatter. Also, note that the documentation is automatically
Re: [Matplotlib-users] UserWarning: Attempting to set identical bottom==top
On Thu, May 5, 2011 at 9:04 PM, C M cmpyt...@gmail.com wrote: On Thu, May 5, 2011 at 10:03 PM, C M cmpyt...@gmail.com wrote: On Thu, May 5, 2011 at 7:58 PM, Benjamin Root ben.r...@ou.edu wrote: On Sun, May 1, 2011 at 4:35 PM, C M cmpyt...@gmail.com wrote: I get this error and would like to know what to do to eliminate it and also what it means: C:\Python25\lib\site-packages\matplotlib\axes.py:2571: UserWarning: Attempting to set identical bottom==top results in singular transformations; automatically expanding. bottom=0, top=0 + 'bottom=%s, top=%s') % (bottom, top)) This is with Matplotlib 1.0.0. Thank you, Che I have seen this happen when the plot is set to use the limits of the data to guide the axes limits, but the data being displayed is either vertical or horizontal. What do you mean by the data being vertical or horizontal? I can get this error with a single point that is plotted on a time vs. values plot. Or even a single point. In other words, if the bounding box encompassing the data being plotted can be reduced to a 1 or 0 dimensional representation, then matplotlib will auto-pad this so that the rest of matplotlib won't crash. It isn't a huge issue as the code is automatically padding the axes to make take the plot out of flat world. The problem is, when I use a py2exe'd app this error occurs and the user sees a message to see the log file for the error. I don't want that at all. It's a bad user experience. The warning message is important because it is usually an indication that the program is doing something wrong. If you (and by you, I mean the program) might be plotting a single point or something that can be reduced to 1 or 0 dimensions, then you should not have the axes automatically set its limits from the data without pads. Because you have a py2exe'ed program, I suspect that whoever packaged the program should be the one to modify that program to choose its axes limits more robustly in order to avoid the warning message. Unless the other developers feel differently, I am against suppressing this warning message. I hope that makes things clearer. Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] UserWarning: Attempting to set identical bottom==top
Because you have a py2exe'ed program, I suspect that whoever packaged the program should be the one to modify that program to choose its axes limits more robustly in order to avoid the warning message. Maybe I have been unclear. I am the sole developer of this application, and I occasionally test it as a py2exe'd app in anticipation of delivering it in that form at some point. I would be happy to modify the program to choose its axes limits more robustly--if I only knew how to do that. That is what I am asking. How should I do that? The data to be plotted is a very simple date plot with dates on the x axis and values (formatted as time) on the y axis. Che -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] List Archive
Is there a list archive I can search to see if a question has been asked before? Thanks, Nate -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] List Archive
On Thursday, May 5, 2011, Nate Gallagher nate.gallag...@yahoo.com wrote: Is there a list archive I can search to see if a question has been asked before? Thanks, Nate http://old.nabble.com/matplotlib---users-f2906.html There are others as well. These are good formviewing the archives. But for searches, I just use google with matplotlib as the first term. Most results usually point to a thread archived on nabble anyway. I hope that helps! Ben Root -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users