[Matplotlib-users] merging two axes from two different figures (Tk canvas) into one
Dear all, I wrote an application allowing to display an imshow image in one part of a Tk GUI and the corresponding colorbar in another part. This allows me to work on the image with more freedom. My problem is then to save the result which implies getting the 2 axes into another figure. I've been fighting for some time but I can't get it right. The problem in the end is that I don't really understand the exact link between: figure - canvas - axes. I guessed that one creates a Figurecanvas which is the GUI link where to put the figure which itself contains the axes. But when I tried to get the axes and put them into a new figure, they don't appear... Can anyone give me a hint on what I did wrong ? I'm using matplotlib v.0.90.1 The code looks something like: -- ## init part ### import matplotlib as mpl mpl.use('TkAgg') from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg ## creating GUI elements ### #create figures self.mplfImageDisplay = mpl.figure.Figure(figsize=(5,4),dpi=100,facecolor='white') self.mplfImageColorbar = mpl.figure.Figure(figsize=(0.7,4),dpi=100,facecolor='white') #add tk.DrawingArea self.cvImageDisplay = FigureCanvasTkAgg(self.mplfImageDisplay,master=leftPaneImage) self.cvImageDisplay.get_tk_widget().pack() self.cvImageColorbar = FigureCanvasTkAgg(self.mplfImageColorbar,master=centerPaneImage) self.cvImageColorbar.get_tk_widget().pack() #pack all in main frame self.cvImageDisplay._tkcanvas.pack() self.cvImageColorbar._tkcanvas.pack() ## adding axes to GUI elements ### #get data (2d matrix) self.finaldata = self.build_data() #define first axes (image) self.axes1 = self.mplfImageDisplay.gca(frameon=False) self.axes1.set_position((0.015,0.02,0.98,0.96)) display = self.axes1.imshow(self.finaldata, origin='upper', aspect='auto', interpolation=interpolation, cmap=imagecolormap, vmin=minvalue, vmax=maxvalue) self.axes1.set_axis_off() #define colorbar self.axes2 = self.mplfImageColorbar.gca() self.axes2.set_position((0.1,0.05,barsize,0.9)) self.colorbar = figcolorbar.colorbar(display, format='%'+legendformat, cax=self.axes2) #set font size colorbartextlist = self.axes2.get_yticklabels() for element in colorbartextlist: element.set_fontsize(fontsize) #display image self.cvimage.show() cvcolorbar.show() ## saving result ### #get current figure image = self.mplfImageDisplay.gca() colorbar = self.mplfImageColorbar.gca() #calculate fig width imagewidth = self.mplfImageDisplay.get_figwidth() colorbarwidth = self.mplfImageColorbar.get_figwidth() totalwidth = imagewidth + colorbarwidth #calculate fig height imageheight= self.mplfImageDisplay.get_figheight() colorbarheight = self.mplfImageColorbar.get_figheight() totalheight = max(imageheight,colorbarheight) #create new figure outputfigure = mpl.figure.Figure(figsize=(totalwidth,totalheight),dpi=100,facecolor='white') #add axes outputfigure.add_axes(axes=image,anchor='w') outputfigure.add_axes(axes=colorbar,anchor='e') #I also tried playing about adding a canvas but it didn't help much #cvouputfigure = FigureCanvasTkAgg(outputfigure) #outputfigure.draw(cvouputfigure.get_renderer()) #save figure outputfigure.savefig(outputfilename) -- _ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] usetex=True
Thanks. I think that's actually unrelated to your patch -- but is new since 0.91.2. Fixed in SVN r4872. Thanks for your help, Mike Paul Novak wrote: The patch for legends works except for LineCollection. For any call to legend(), I get the errors below, Paul Traceback (most recent call last): File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py, line 331, in expose_event self._render_figure(self._pixmap, w, h) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtkagg.py, line 75, in _render_figure FigureCanvasAgg.draw(self) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_agg.py, line 257, in draw self.figure.draw(self.renderer) File /usr/lib/python2.5/site-packages/matplotlib/figure.py, line 698, in draw for a in self.axes: a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/axes.py, line 1397, in draw a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/legend.py, line 206, in draw h.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 480, in draw lineFunc(renderer, gc, tpath, affine.frozen()) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 740, in _draw_dashed renderer.draw_path(gc, path, trans) ValueError: Dash sequence must be an even length sequence; found 1 Traceback (most recent call last): File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py, line 331, in expose_event self._render_figure(self._pixmap, w, h) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtkagg.py, line 75, in _render_figure FigureCanvasAgg.draw(self) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_agg.py, line 257, in draw self.figure.draw(self.renderer) File /usr/lib/python2.5/site-packages/matplotlib/figure.py, line 698, in draw for a in self.axes: a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/axes.py, line 1397, in draw a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/legend.py, line 206, in draw h.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 480, in draw lineFunc(renderer, gc, tpath, affine.frozen()) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 740, in _draw_dashed renderer.draw_path(gc, path, trans) ValueError: Dash sequence must be an even length sequence; found 1 Traceback (most recent call last): File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py, line 331, in expose_event self._render_figure(self._pixmap, w, h) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtkagg.py, line 75, in _render_figure FigureCanvasAgg.draw(self) File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_agg.py, line 257, in draw self.figure.draw(self.renderer) File /usr/lib/python2.5/site-packages/matplotlib/figure.py, line 698, in draw for a in self.axes: a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/axes.py, line 1397, in draw a.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/legend.py, line 206, in draw h.draw(renderer) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 480, in draw lineFunc(renderer, gc, tpath, affine.frozen()) File /usr/lib/python2.5/site-packages/matplotlib/lines.py, line 740, in _draw_dashed renderer.draw_path(gc, path, trans) ValueError: Dash sequence must be an even length sequence; found 1 Michael Droettboom wrote: [I'm bringing this back to the list. Hope you don't mind.] I've been doing a lot of non-matplotlib work lately and this fell off my radar. Thanks for the reminder. The patch looks good to me. I'm not concerned about doing all this in _get_handles as opposed to Legend.__init__. I actually think it's better in _get_handles because then it's more connected to the creation of the handles themselves. (And of course _get_handles is only ever called from __init__ anyway, so it really is just an organizational extension of __init__). I moved all references to _xdata to _get_handles to be consistent. The one concern I had is that _xdata is being stored as a member variable, which implicitly assumes that it will be the same for all handles. After your patch, it can be different for each handle -- for instance a line made of markers vs. dashing. So I've just made it a local variable to _get_handles and recreate it separately for each handle. There's no reason to try to share something so small, and it just feels safer (fewer potential side effects) that way. I've committed this in r4871. Please check it out and kick the tires with all the test cases you came up with along the way and let me know how it goes. Cheers, Mike Paul
Re: [Matplotlib-users] Bug in pylab?
I'm having an enormous sense of deja vu... There was a very similar bug filed here, http://sourceforge.net/tracker/index.php?func=detailaid=1757315group_id=80706atid=560720 which I thought I had resolved in revision 4197 (which would have made it into all of the 0.91.x releases). My fix there was just to forcibly set the plot back to linear in cla() -- the idea being that if a new plot is created and hold is False, it is forcibly set back to linear (i.e. pristine state) by calling set_xscale('linear') and set_yscale('linear), which resets both the transform and the locators/formatters etc. This fix works whether you use loglog() to create the plot, or plot() followed by set_?scale(). But reading Darren's new bug report makes me wonder if my fix was correct. To be honest, I'm a little confused by the bug report, not out of any lack of clarity on Darren's part, but I think due to insufficient understanding of the problem. As assumption about the purpose of cla is that is should return the plot to a pristine state -- and in this case that means linear axes. But are you suggesting that sometimes that is not the case? Just so we're on the page, does this bug still occur post r4197 and with 0.91.x, or is this a 0.90.1 issue? Cheers, Mike Darren Dale wrote: Hi Lorenzo, On Tuesday 15 January 2008 4:14:24 pm Lorenzo Isella wrote: Dear All, I am sending this email out of frustration, but I hope that someone will be able to tell me what is going on. I am using pylab on a Debian testing box. I have the feeling that there is some problem with pylab when I alternate, as I am doing now, many linear and log-log plots. Very often, pylab complains about the fact that I cannot take the log of a negative number even if all the quantities are positive or even if I have replaced the loglog with a linear plot... An example (sorry but there are long arrays involved and I cannot reproduce all my code here): #! /usr/bin/env python import scipy as s import numpy as n import pylab as p #from rpy import r #import distance_calc as d_calc # now I try performing a least-square fitting import scipy.optimize as sopt #do my stuff here print my_n_clus_fit is, , my_n_clus_fit print my_r_sq_fit,my_r_sq_fit print n_clu_rep2 is, , n_clu_rep2 print R_sq is, R_sq p.plot(n_clu_rep2,R_sq,bo,my_n_clus_fit,my_r_sq_fit, ro) p.xlabel('particles in cluster') p.ylabel('R square') #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part')) p.title('Cluster-size vs average radius of gyration') p.grid(True) p.savefig(R_gyr_vs_N_fit.pdf) p.hold(False) and the relevant part of the output is: [...] Traceback (most recent call last): File ./r_gyr.py, line 322, in ? p.plot(n_clu_rep2,R_sq,bo,my_n_clus_fit,my_r_sq_fit, ro) File /usr/lib/python2.4/site-packages/matplotlib/pylab.py, line 2028, in plot ret = gca().plot(*args, **kwargs) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 2540, in plot self.autoscale_view(scalex=scalex, scaley=scaley) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 1207, in autoscale_view self.set_xlim(XL) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 1493, in set_xlim raise ValueError('Cannot set nonpositive limits with log transform') ValueError: Cannot set nonpositive limits with log transform I think this is a bug. It sounds like the same issue I reported a while back: http://www.nabble.com/Cannot-set-nonpositive-limits-with-log-transform-to12154187.html I havent had a chance to look into a solution. I filed a bug report at sourceforge (1872462). I'm worried the fix will be disruptive, but several people have run into this. I'm sorry you got bit as well. Darren - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] FuncFormatter and Colorbar
Hi MAtthias, yes, I can confirm this behavior. This is what I get as well. But the solution is easy: just get rid of th line cb.ax.yaxis.set_major_formatter(formatter) We don't need it anymore and it messes it all up. Without it, it should work. Greetings, Thorsten 2008/1/11, Matthias Michler [EMAIL PROTECTED]: Hi Thorsten, On Wednesday 09 January 2008 15:35, Thorsten Kranz wrote: Hi list, Hi Matthias, I found another way to deal with this problem. when defining the colorbar, one can give an additional kwarg format, so by defining the kwarg format=formatter, we solved the problem. I'm happy that your problem disappeared, but I still have a question. On my system the problem still exist, if I use format=formatter in colorbar and after that use cb.ax.yaxis.set_major_formatter(formatter) in the example-code of my last email. Can anybody confirm this behaviour (data range 0.0 ... 0.54 - 0.0 ... 0.95)? And if so: Is this the expected behaviour? best regards, Matthias Anyway, I think an option as Matthias implemented would be very handy for all those users like us here in Germany who might want to have the numbers formatted with commata. Greetings, Thorsten 2008/1/9, Matthias Michler [EMAIL PROTECTED]: Hello list, Hello Thorsten, On Wednesday 09 January 2008 11:38, Thorsten Kranz wrote: I have a question concerning reformatting of axis-ticks via the FuncFormatter-class. In german, it's common to use a comma as separator for decimal numbers instead of a dot. To realize it in matplotlib, I do something like from matplotlib.ticker import FuncFormatter import pylab pylab.figure() formatter = FuncFormatter(lambda x,pos: (%.2f%x).replace(.,,)) ax = pylab.axes() ax.xaxis.set_major_formatter(formatter) ax.yaxis.set_major_formatter(formatter) ax.plot(pylab.arange(0,1,0.1),pylab.arange(0,1,0.1)) This works fine for me, I had the same idea ;-). The problem is that you have a fixed number of digits behind the comma, which is not the desirable behaviour during zoom. I changed the ticker.py/ axes.py files to circumwait this disadvantage. I attached a patch showing my changes and maybe somebody can test it. You can activate it using: ax.ticklabel_format(style='comma') for an ScalarFormatter but I encounter a problem when I do an imshow-command with a colorbar. In the imshow-axes, it's o.k., but for the colorbar it doesn't really work. I do cb = pylab.colorbar() cb.ax.yaxis.set_major_formatter(formatter) and, actually, all dots are replaced by com9mata, but the values are also changed! E.g. instead of the old values (without formatter) from 0-0.54, the values are increased to 0-0.95. [...] Can anyone explain why it doesn't work out as I expect it to work? I don't know were the problem comes from. I attached your example in a slitly modified version and this shows that the problem is not due to your special formatting. It occurs with matplotlib.ticker.ScalarFormatter, too. best regards, Matthias Or is there a better, more standard way to substitute the dots by commata? Thanks, Thorsten - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl ace ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bug in pylab?
On Wednesday 16 January 2008 08:22:45 am Michael Droettboom wrote: I'm having an enormous sense of deja vu... There was a very similar bug filed here, http://sourceforge.net/tracker/index.php?func=detailaid=1757315group_id=8 0706atid=560720 I think it is identical, I overlooked the original bug report... which I thought I had resolved in revision 4197 (which would have made it into all of the 0.91.x releases). and it appears to be fixed on my machine (caveat below). Lorenzo, what matplotlib version are you using? My fix there was just to forcibly set the plot back to linear in cla() -- the idea being that if a new plot is created and hold is False, it is forcibly set back to linear (i.e. pristine state) by calling set_xscale('linear') and set_yscale('linear), which resets both the transform and the locators/formatters etc. This fix works whether you use loglog() to create the plot, or plot() followed by set_?scale(). But reading Darren's new bug report makes me wonder if my fix was correct. To be honest, I'm a little confused by the bug report, not out of any lack of clarity on Darren's part, but I think due to insufficient understanding of the problem. As assumption about the purpose of cla is that is should return the plot to a pristine state -- and in this case that means linear axes. But are you suggesting that sometimes that is not the case? If you have hold=True, and the x or y scale is log, repeated calls to plot() will add new lines to the plot without changing the scaling. If hold is instead False, one might reasonably expect that future calls to plot would replace the old line with the new one, again without changing the scaling. That would be consistent. Instead, the scaling changes. Just so we're on the page, does this bug still occur post r4197 and with 0.91.x, or is this a 0.90.1 issue? I don't see the bug in svn. Lorenzo? Darren Dale wrote: Hi Lorenzo, On Tuesday 15 January 2008 4:14:24 pm Lorenzo Isella wrote: Dear All, I am sending this email out of frustration, but I hope that someone will be able to tell me what is going on. I am using pylab on a Debian testing box. I have the feeling that there is some problem with pylab when I alternate, as I am doing now, many linear and log-log plots. Very often, pylab complains about the fact that I cannot take the log of a negative number even if all the quantities are positive or even if I have replaced the loglog with a linear plot... An example (sorry but there are long arrays involved and I cannot reproduce all my code here): #! /usr/bin/env python import scipy as s import numpy as n import pylab as p #from rpy import r #import distance_calc as d_calc # now I try performing a least-square fitting import scipy.optimize as sopt #do my stuff here print my_n_clus_fit is, , my_n_clus_fit print my_r_sq_fit,my_r_sq_fit print n_clu_rep2 is, , n_clu_rep2 print R_sq is, R_sq p.plot(n_clu_rep2,R_sq,bo,my_n_clus_fit,my_r_sq_fit, ro) p.xlabel('particles in cluster') p.ylabel('R square') #p.legend(('beta=1e-2,100 part','beta=1e-1, 100 part', 'beta=1e-1, 200 part')) p.title('Cluster-size vs average radius of gyration') p.grid(True) p.savefig(R_gyr_vs_N_fit.pdf) p.hold(False) and the relevant part of the output is: [...] Traceback (most recent call last): File ./r_gyr.py, line 322, in ? p.plot(n_clu_rep2,R_sq,bo,my_n_clus_fit,my_r_sq_fit, ro) File /usr/lib/python2.4/site-packages/matplotlib/pylab.py, line 2028, in plot ret = gca().plot(*args, **kwargs) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 2540, in plot self.autoscale_view(scalex=scalex, scaley=scaley) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 1207, in autoscale_view self.set_xlim(XL) File /usr/lib/python2.4/site-packages/matplotlib/axes.py, line 1493, in set_xlim raise ValueError('Cannot set nonpositive limits with log transform') ValueError: Cannot set nonpositive limits with log transform I think this is a bug. It sounds like the same issue I reported a while back: http://www.nabble.com/Cannot-set-nonpositive-limits-with-log-transform-to 12154187.html I havent had a chance to look into a solution. I filed a bug report at sourceforge (1872462). I'm worried the fix will be disruptive, but several people have run into this. I'm sorry you got bit as well. Darren - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Darren S. Dale, Ph.D. Staff Scientist Cornell High Energy
Re: [Matplotlib-users] Is Gtk draw() slow?
Michael Droettboom wrote: It's sort of a pygtk issue -- it would have to be rewritten to take numpy arrays not quite -- it would have to be re-written to use the array interface, which is different, as that can be done without requiring numpy, or its headers. which is probably unlikely to happen in the official codebase. That was true before the array interface, when supporting arrays essentially meant a dependency on numpy. That's not longer true, so it's quite likely that the pygtk folks would accept a patch -- someone still would need to write that patch, though! -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] TrueType font embedding in eps problem.
Ok... I'm running python 2.5 on winxp. I recently upgraded from matplotlib 88ish to 91.1, and now the font embedding in eps files no longer works for me: all fonts end up as paths when I open an eps file in illustrator, and I can't do any font editing like I could before I upgraded. I found a reference to changing ps.fonttype to 42 on one of the matplotlib faq pages to embed the entire truetype font in the eps file, but when I do that illustrator can't open the eps file, failing with The operation cannot complete because of an unknown error. How do I make the fonts editable in illustrator again? Jordan - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Distance of yticklabels from axis
Hi list! I have another question, which hopefully is not that hard. I want to control the distance of the ticklabels from the axiy. How can I do this? Maybe by one of the rc-Parameters? Thanks in advance, Thorsten - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] multiline math text
- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Distance of yticklabels from axis
On Wednesday 16 January 2008 01:02:04 pm Thorsten Kranz wrote: Hi list! I have another question, which hopefully is not that hard. I want to control the distance of the ticklabels from the axiy. How can I do this? Maybe by one of the rc-Parameters? Yes, see the (x,y)tick.(major,minor).pad parameter. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] x axis alignment with bar graph
bump. please...? Begin forwarded message: I have some code that produces a series of graphs of data over time. For the most part it works well, but for certain combinations of dates the two plots do not line up, due to the width of the bars in the first subplot. What is the best way for force my second subplot's x axis to be identical to that of the first subplot? Thanks! Here is minimal code reproducing the problem: import matplotlib from datetime import * import time from pylab import * def toOrd(strDate): return datetime(*time.strptime(strDate,%m/%d/%y)[0:5]).toordinal() def main(): startDate = toOrd(05/24/05) endDate = toOrd(11/21/06) dates = range(startDate,endDate,7) figure(1) axis = subplot(211,axisbelow=True) plot_date(dates,dates,visible = False) axis.bar(dates,dates, width=3.0) axis = subplot(212,axisbelow=True) plot_date(dates,dates) #,'-',color = priceColor) show() if __name__ == '__main__': main() - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] x axis alignment with bar graph
Thanks Eric! Here is corrected code that works: import matplotlib from datetime import * import time from pylab import * def toOrd(strDate): return datetime(*time.strptime(strDate,%m/%d/%y)[0:5]).toordinal() def main(): startDate = toOrd(05/24/05) endDate = toOrd(11/21/06) dates = range(startDate,endDate,7) figure(1) ax1 = subplot(211,axisbelow=True) plot_date(dates,dates,visible = False) ax1.bar(dates,dates, width=3.0) ax2 = subplot(212,axisbelow=True, sharex=ax1) plot_date(dates,dates) #,'-',color = priceColor) show() if __name__ == '__main__': main() On Jan 16, 2008, at 1:02 PM, Eric Firing wrote: John Harrison wrote: bump. please...? Begin forwarded message: I have some code that produces a series of graphs of data over time. For the most part it works well, but for certain combinations of dates the two plots do not line up, due to the width of the bars in the first subplot. What is the best way for force my second subplot's x axis to be identical to that of the first subplot? Check the sharex kwarg. In the examples directory, see ganged_plots.py, shared_axis_demo.py, and any others that include the sharex kwarg. Eric Thanks! Here is minimal code reproducing the problem: import matplotlib from datetime import * import time from pylab import * def toOrd(strDate): return datetime(*time.strptime(strDate,%m/%d/%y)[0:5]).toordinal() def main(): startDate = toOrd(05/24/05) endDate = toOrd(11/21/06) dates = range(startDate,endDate,7) figure(1) axis = subplot(211,axisbelow=True) plot_date(dates,dates,visible = False) axis.bar(dates,dates, width=3.0) axis = subplot(212,axisbelow=True) plot_date(dates,dates) #,'-',color = priceColor) show() if __name__ == '__main__': main() - --- - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ - --- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] formatting axis to percent notation
On Jan 16, 2008 1:03 PM, Kevin Christman [EMAIL PROTECTED] wrote: I'm new to matplotlib. Currently the x-axis shows numbers from 0 to 1. I would like it to show it in percent notation (e.g. 0% to 100%). How do I do this in matplotlib? You can either multiply your x data by 100 (where x is a numpy array) plot(x*100, y) or set a custom formatter from matplotlib.ticker import FuncFormatter def myfunc(x, pos=0): return '%1.2f''%(100*x) ax = subplot(111) ax.plot(x, y) ax.xaxis.set_major_formatter(FuncFormatter(myfunc)) There is a section on custom tick formatting in the user's guide on the web site JDH JDH - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Is Gtk draw() slow?
On Jan 15, 2008 7:46 AM, Michael Droettboom [EMAIL PROTECTED] wrote: Ah -- just thought of something else. If I adjust simple_plot_fps.py to have 100,000 data points rather than 1,000 I see something that starts to match with what you're seeing: GtkAgg: wallclock: 4.23297405243 user: 3.33 fps: 23.6240522057 Gtk: wallclock: 15.0203828812 user: 14.92 fps: 6.65761990165 TkAgg: wallclock: 4.8252530098 user: 4.67 fps: 20.7243018754 You can see that the Gtk time is starting to explode. If I go to 1,000,000 points, Gtk runs out of memory before the first plot, whereas the other two continue to chug along at a reasonable pace. From looking at the code, I suspect the crucial difference is that the Gdk backend uses the Python sequence API (rather slow) to access the data as it gets rendered, whereas GtkAgg uses the numpy array interface which is essentially raw access to a C array. This is not likely to be the culprit -- for drawing markers, the old matplotlib API made a separate call to draw_polygon for every marker, with a new gc each time. Many moons ago, we implemented draw_markers as a renderer method to avoid this problem. For hundreds of thousands of markers, we saw performance benefits of 25x to 100x. The backends which implement draw_markers (Agg and PS) get the benefits, but the other backends which did not are still slow. Basically it is a problem with a lot of redundant function call overhead. The backend_bases renderer method _draw_markers discusses this a little bit (it is underscore hidden). My guess is this difference will not be so pronounced on the trunk. JDH - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] TrueType font embedding in eps problem.
Setting ps.useafm = True while ps.fonttype = 42 allows illustrator to open the eps files again and gives me back text editing capability, but I don't have any control over the typeface anymore, it just defaults to Helvetica. Jordan - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] colorbar and set_under
Hi folks, I have encountered a problem using colorbar and set_under with a color map that has only 32 colors. The downward arrow is not filled with the correct color. If 64 colors are used, the arrow is filled correctly. I actually want 8 colors. The test code is essentially image_masked.py from the 0.90.0 examples. if I use: palette = cm.get_cmap(gray, 64) the plot is OK. if I use: palette = cm.get_cmap(gray, 32) it is not OK. In both cases, the upper arrow is the correct color. I am using matplotlib version 0.90.0. Here is the complete code: #!/usr/bin/env python '''imshow with masked array input and out-of-range colors. ''' from pylab import * import matplotlib.numerix.ma as ma import matplotlib.colors as colors delta = 0.025 x = y = arange(-3.0, 3.0, delta) X, Y = meshgrid(x, y) Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) Z = 10 * (Z2-Z1) # difference of Gaussians # Set up a colormap: #palette = cm.gray # OK palette = cm.get_cmap(gray,32)# Not OK #palette = cm.get_cmap(gray,64) # OK palette.set_over('r', 1.0) palette.set_under('g', 1.0) palette.set_bad('b', 1.0) # Alternatively, we could use # palette.set_bad(alpha = 0.0) # to make the bad region transparent. This is the default. # If you comment out all the palette.set* lines, you will see # all the defaults; under and over will be colored with the # first and last colors in the palette, respectively. Zm = ma.masked_where(Z 1.2, Z) # By setting vmin and vmax in the norm, we establish the # range to which the regular palette color scale is applied. # Anything above that range is colored based on palette.set_over, etc. im = imshow(Zm, interpolation='bilinear', cmap=palette, norm = colors.Normalize(vmin = -1.0, vmax = 1.0, clip = False), origin='lower', extent=[-3,3,-3,3]) title('Green=low, Red=high, Blue=bad') # extend choices are both, min, max and neither colorbar(im, extend='both', shrink=0.8) show() -- Ms. Carol A. Leger SRI International Phone: (650) 859-4114 333 Ravenswood Avenue G-273 Menlo Park, CA 94025e-mail: [EMAIL PROTECTED] - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Cross hair and polygon drawing tools.
For some simple but effective Python code you can use to create a mask similar to that provided by the Matlab roipoly function, see http://www.ariel.com.au/a/python-point-int-poly.html http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be quite effective. Venkat Ramanan wrote: Hi, I'm looking for something analogous to Matlab's ginput() and roipoly(). ginput() basically displays a crosshair on the current figure and allows us to select points by clicking on it. It returns the x,y coordinates of the points. roipoly() allows us to define a polygon by clicking on the figure and returns a logical matrix, where ones represent the insides of the polygon and zeros outside. Any pointers are appreciated. I recently found matplotlib and started porting some of my Matlab scripts to it. Ubuntu feisty (7.04), matplotlib 0.87.7. I can upgrade though. Thanks, Venkat. - SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- View this message in context: http://www.nabble.com/Cross-hair-and-polygon-drawing-tools.-tp14199642p14626348.html Sent from the matplotlib - users mailing list archive at Nabble.com. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Tkagg segfault on standard examples
Hi all, I am unable to use the TkAgg backend on opensuse linux 10.2 or 10.3? The standard examples embedded_in_tk.py embedded_in_tk2.py end up with a segmentation fault. In debugger, the following message is reported Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7caf6c0 (LWP 17262)] PyAggImagePhoto (clientdata=0x0, interp=0x84dfcc0, argc=5, argv=0xbfdb09fc) at src/_transforms.h:362 362 Point* ll_api() {return _ll;} Current language: auto; currently c++ I've tried it first with the pre-built RPMs from the site http://download.opensuse.org/repositories/science/openSUSE_10.3/i586/python-matplotlib-tk-0.91.1-3.1.i586.rpm Then, I deleted it and built matplotlib using current version matplotlib-0.91.2.tar.gz On ubuntu, the above listed examples are running. Similar problem has been reported earlier. http://www.mail-archive.com/matplotlib-users%40lists.sourceforge.net/msg02822.html It seems to be some tcl/tk installation problem. Does anyone have an idea how to fix it. Lot of thanks R. Chudoba - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] gtk backend failure on systems without gtk
On some OSX systems, pylab is failing on importing pylab because of lack of GTK. This appears to be a bug; if the system doesnt have gtk, it should simply not import that backend to begin with. from matplotlib import pylab Traceback (most recent call last): File stdin, line 1, in module File /Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5- macosx-10.5-i386.egg/matplotlib/pylab.py, line 292, in module from matplotlib.pyplot import * File /Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5- macosx-10.5-i386.egg/matplotlib/pyplot.py, line 39, in module new_figure_manager, draw_if_interactive, show = pylab_setup() File /Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5- macosx-10.5-i386.egg/matplotlib/backends/__init__.py, line 24, in pylab_setup globals(),locals(),[backend_name]) File /Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5- macosx-10.5-i386.egg/matplotlib/backends/backend_gtkagg.py, line 10, in module from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\ File /Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5- macosx-10.5-i386.egg/matplotlib/backends/backend_gtk.py, line 6, in module import gobject ImportError: No module named gobject - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] parametric plot of two sets of discrete data
On Jan 2, 2008 10:25 PM, Aitor Gonzalez [EMAIL PROTECTED] wrote: Hi, I have some two sets of data with their x- and y-coordinates, (x1, y1) and (x2, y2). I want to plot these curves as a parametric plot: # from numpy import * from pylab import * t = arange ( 0.0 , pi/2 , 0.05) x1= cos(t) y1 = -sin(t) x2 = -1+2/pi*t y2 = -2/pi*t I think you want something like plot(x1, y1, 'g-', x2, y2, 'r-') - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Cross hair and polygon drawing tools.
On Jan 4, 2008 4:33 PM, Mephisto [EMAIL PROTECTED] wrote: For some simple but effective Python code you can use to create a mask similar to that provided by the Matlab roipoly function, see http://www.ariel.com.au/a/python-point-int-poly.html http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be quite effective. matplotlib implements these algorithms in C -- see matplotlib.nxutils.pnpoly for a testing inclusion of a single point, and matplotlib.nxutils.points_inside_poly for testing multiple points. There is some example code using the latter function at http://matplotlib.sf.net/examples/lasso_demo.py. Not sure why this example is not working for Venkat. JDH - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] gtk backend failure on systems without gtk
On Jan 13, 2008 7:26 PM, Christopher Fonnesbeck [EMAIL PROTECTED] wrote: On some OSX systems, pylab is failing on importing pylab because of lack of GTK. This appears to be a bug; if the system doesnt have gtk, it should simply not import that backend to begin with. matplotlib does not do runtime checking to see if a backend is available (arguably it should, but it does not_. It does do compile time checking, and if gtk was available at compile time it will spit out a default matplotlib rc file which uses gtkagg. If you ship this to your users who do not have gtk, it can cause problems (you can tweak this with setup.cfg). You may want to make tkagg the default backend if you are distributing binaries, since it is most likely to work on the user side. JDH - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] colorbar and set_under
Carol Leger wrote: Hi folks, I have encountered a problem using colorbar and set_under with a color map that has only 32 colors. The downward arrow is not filled with the correct color. If 64 colors are used, the arrow is filled correctly. I actually want 8 colors. The test code is essentially image_masked.py from the 0.90.0 examples. if I use: palette = cm.get_cmap(gray, 64) the plot is OK. if I use: palette = cm.get_cmap(gray, 32) it is not OK. In both cases, the upper arrow is the correct color. I am using matplotlib version 0.90.0. Carol, It works for me even with 8 colors, using the svn version of mpl. There have been a lot of changes between 0.90.0 and the present svn trunk (including a heart transplant by Mike D.), but I would not have expected any changes that would change the behavior you describe. I can't think of any way a bug would have made a break point in behavior between 32 and 64 colors. I'm baffled. Can you install and run the svn version? Or the latest release (which does not include the new heart)? I also tried the svn maintenance branch, which is virtually identical to the last release, and it works the same as the trunk. Eric - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users