Re: [Matplotlib-users] matshow?
Fernando Perez wrote: [...] Frankly, I don't care how it's done: I wrote matshow long ago, back when axis('scaled') didn't exist in the first place. If the same result can be achieved by other means that are cleaner, I'm sure John will accept a patch. One of the matshow anomalies is that it is a pylab function only instead of a wrapper for an Axes method, so I made a new Axes.matshow(), and a temporary matshow1() pylab function that calls it. Differences between matshow() and matshow1(): 1) The latter labels the *centers* of the squares representing the matrix elements, starting from zero. Tick values are consequently integers. 2) matshow1 uses the same function as matshow (figaspect()) to determine the window dimensions, but keeps the matrix elements square when they would be stretched in matshow. I can change this back to the matshow behavior if desired. All I need regularly in my work is the ability to plot a matrix such that both the axis AND the enclosing figure (which determines the size of the resulting EPS files for publications or talks) have the aspect ratio of the actual matrix. How that result is achieved is really immaterial to me. I suspect that what you would actually prefer is better automated figure sizing so that it would always nicely enclose the axes with their labels, titles, etc., correct? There is nothing magic about having the actual aspect ratio of the figure exactly match that of the axes box? (Not that I can easily achieve the nice wrapping result--this is just to clarify the ideal.) matshow does what I need so I use it, but I have no particular attachment to the code other than the fact that it happens to work correctly. That's a bonus in my book. Absolutely! Another anomaly of matshow (presently preserved in matshow1) is the returnall kwarg; this seems like the sort of thing that should either be supported by all pylab functions, or by none. The argument for none is that one can easily use gcf() and gca() to get the other two arguments. Do you want to keep the returnall kwarg? Eric - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Question about matshow
Hi, I have some problems to combine a matshow object with a canvas. Here is a little piece of code that illustrates my problem. It displays a matshow object when pressing a button. I would like to embed the matshow object into a canvas of a fixed dimension. The code I wrote does the opposite i.e. it is the canvas that adapts its size and not the matshow object. Would you have any hints ? ** from Tkinter import * from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import pylab def display(): mat = pylab.zeros((100,100)) pylab.ioff() image = pylab.matshow(mat) pylab.ion() can = FigureCanvasTkAgg(image, master=frame) can.show() can.get_tk_widget().grid(row = 0,column = 0) root = Tk() frame = Frame(root) frame.grid(row = 0,column = 0) canvas = Canvas(frame, width = 240, height = 240, relief = sunken, bg = white) canvas.grid() button = Button(root,text=DisplayMatrix,command = display) button.grid(row = 1,column = 0) Thank you very much Eric - Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Displaying several points with different colors
Hi, I tried it again, and now it works like charm with numpy arrays. I do not understand why it did not work before, but it works now, it's all that matters :) But 3D is another problem... Matthieu 2007/3/14, Eric Firing [EMAIL PROTECTED]: Matthieu Brucher wrote: What version of mpl are you using? The latest, I compiled it from the source as FC5 has a very old version - can't update myself the distribution - In recent versions, the collections should accept 2D numpy arrays as well as any sequence of tuples (and several other possibilities). For 2D plots, numpy arrays is accepted - but not for colors, it tells me there is a problem with tuples, I do not remember exactly, but I can check the error tomorrow -. Mathieu, Did you come up with a minimal example of this? If so, please send it to me directly. I would like to follow up on it. Thanks. Eric - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Feature request: make labels accept non-string arguments
Thanks!! I really appreciate the fast action! Vicki Eric Firing wrote: Victoria G. Laidler wrote: [...] It would be extremely useful if xlabel, ylabel, title, and possibly legend could be made smart enough to attempt to call a __str__ method on the objects they are passed, so that xlabel(MyObject) behaves as intelligently as print MyObject does. [...] Any chance of getting this implemented? Vicki, Done in svn. Eric Hopefully, Vicki Laidler, STScI - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Question about matshow
Pellegrini Eric wrote: Hi, I have some problems to combine a matshow object with a canvas. Here is a little piece of code that illustrates my problem. It displays a matshow object when pressing a button. I would like to embed the matshow object into a canvas of a fixed dimension. The code I wrote does the opposite i.e. it is the canvas that adapts its size and not the matshow object. Would you have any hints ? I suspect this problem will be solved by a change I made to svn last night, providing a matshow Axes method that you would use in place of pylab.matshow. Axes.matshow() simply makes and returns the image; it does not make a figure or set its dimensions, so you have full control over that. Eric ** from Tkinter import * from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import pylab def display(): mat = pylab.zeros((100,100)) pylab.ioff() image = pylab.matshow(mat) pylab.ion() can = FigureCanvasTkAgg(image, master=frame) can.show() can.get_tk_widget().grid(row = 0,column = 0) root = Tk() frame = Frame(root) frame.grid(row = 0,column = 0) canvas = Canvas(frame, width = 240, height = 240, relief = sunken, bg = white) canvas.grid() button = Button(root,text=DisplayMatrix,command = display) button.grid(row = 1,column = 0) Thank you very much Eric Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses http://fr.rd.yahoo.com/evt=42054/*http://fr.answers.yahoo.com. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pylab vs. embedding in wx
I am learning the hard way that I don't know as much about matplotlib as I thought I did except for how to use pylab. I think I have managed to create a figure, add an axis, and plot something on it without pylab, but I don't know how to do the equivalent of show(). draw() needs a renderder and I can't seem to figure out how to create one. Here is what I have done so far: myfig = pylab.Figure() myaxes=myfig.add_axes((0,1,0,1)) t=arange(0,1,0.01) y=sin(2*pi*t) myaxes.plot(t,y) What do I need to do to show the plot from the command line in IPython (i.e. if I actually want to use pylab instead of OO)? I may be going about this the wrong way and it may be easier just to set up some imports of pylab that only trigger inside of functions, but I would like to have functions that are useful either from the IPython command line or in OOP situations. Following the examples for WX, I am doing this at the top of my OOP modules: from matplotlib.backends.backend_wxagg import Toolbar, FigureCanvasWxAgg from matplotlib.figure import Figure . . . class mplpanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1) self.fig = Figure((5,5), 75) self.canvas = FigureCanvasWxAgg(self, -1, self.fig) And the my drawing commands operate on self.fig and then the last line of all plotting functions is self.canvas.draw(). So, it would be nice if my utility functions took a figure instance as an input and operated on it. Am I making any sense? Am I going about this revision in a good way? Thanks, Ryan On 3/15/07, Ryan Krauss [EMAIL PROTECTED] wrote: Thanks John. I know I have some clean up to do, I just want to do it right so it isn't an annual (or more often) thing On 3/15/07, John Hunter [EMAIL PROTECTED] wrote: On 3/15/07, Ryan Krauss [EMAIL PROTECTED] wrote: How should I be using matplotlib/pylab in my utility scripts so that they are compatible with embedding in wx? A good rule of thumb is to never import pylab at the top level for modules that need to be imported. In my own code, I often do something like def somefunc(figfunc): fig = figfunc() ax = fig.add_subplot(111) ax.plot([1,2,3]) and then I can call it with somefunc(pylab.figure) or a custom func that generates a GUI embedded figure instance. Eg, in my GTKApps, I have a functor like gtk_figure that returns a function that creates a figure embedded in a GTK window. In basemap, Jeffrey Whitaker does something like the following def somefunc(ax=None): if ax is None: import pylab ax = pylab.gca() Here the pylab import is triggered only when the function is called with default arguments. That way you can use it from GUI code without triggering a pylab import like somefunc(ax) and from other code where you want pylab do do everything with somefunc() I'm afraid you have some cleanup to do. Mixing pylab with embedded GUI code is a recipe for pain and misery. JDH - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pylab vs. embedding in wx
Ryan, In my (limited) experience, it's dicey to mix pylab's plotting functionality and the OO API. I guess I'm a little unclear exactly what your use case is for this. It sounds like you're goal is to create a library of functions that operate on Figure instances, perhaps so you can use them both interactively and as part of a wxPython application. If that's the case, I'd recommend you try using pylab's gcf() and draw () to acquire and redraw the current Figure instance from within IPython. You can also save the return value of pylab's figure(), which returns a Figure that's already been attached to the appropriate renderer. This way you can use the OO API for plotting without having to futz with the drawing machinery directly. This script might give you some ideas about how to structure your code. It contains several of the MPL examples re-coded as functions that accept a Figure instance and use the OO API for plotting. http://svn.csrri.iit.edu/mr-software/wxmpl/trunk/demos/plotting.py Ken - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pylab vs. embedding in wx
Thanks to Ken and John, I think I am off and running. Nice work on wxmpl Ken! I think it fills a significant need. The two attached files show a ridiculously simple example of what I am planning to do. It may be completely obvoius to others. test_plot.py is an example of a module that can be used from the command line with pylab and IPython and it can also be imported into a WX app (as demonstrated by wx_compatible.py). So, I will edit my data processing scripts to use this approach. Thanks again, Ryan On 3/19/07, Ryan Krauss [EMAIL PROTECTED] wrote: Sorry, I just googled wxmpl and found your page and am now downloading it. I may have a more intelligent question momentarily. You may ignore that part of my response. Ryan On 3/19/07, Ryan Krauss [EMAIL PROTECTED] wrote: Thanks for your thoughts Ken. Sorry, I assumed a bit on the context of my comments. I have some data processing utility scripts and I want to now use with a WX application. The problem is that the utility modules were written without any thought of this future use in mind and in all of them I have something like from pylab import figure, cla, clf, plot, semiliogx, show, ... at the top. This makes them completely incompatible with embedding in a WX application. So, I need to re-write them and I want to know how to do that best. John had some suggestions and I had some new questions as I tried to act on his thoughts. So, the actual plotting functions don't have to be re-useable in both contexts, but it would be nice. I can't actually run your code because I don't have the wxmpl.py module. Looking at it, it looks like a really nice set of functions that work cleanly with embedding in a backend. How could I call one of the functions from the command line? Could I do something like: import plotting, pylab myfig = pylab.figure() plotting.plot_simple(myfig) and would I need any additional commands to actually show the figure? Let me know if that makes sense and please send me the wxmpl.py file or let me know where I can get it. Thanks again, Ryan On 3/19/07, Ken McIvor [EMAIL PROTECTED] wrote: Ryan, In my (limited) experience, it's dicey to mix pylab's plotting functionality and the OO API. I guess I'm a little unclear exactly what your use case is for this. It sounds like you're goal is to create a library of functions that operate on Figure instances, perhaps so you can use them both interactively and as part of a wxPython application. If that's the case, I'd recommend you try using pylab's gcf() and draw () to acquire and redraw the current Figure instance from within IPython. You can also save the return value of pylab's figure(), which returns a Figure that's already been attached to the appropriate renderer. This way you can use the OO API for plotting without having to futz with the drawing machinery directly. This script might give you some ideas about how to structure your code. It contains several of the MPL examples re-coded as functions that accept a Figure instance and use the OO API for plotting. http://svn.csrri.iit.edu/mr-software/wxmpl/trunk/demos/plotting.py Ken def myplot(fig, x, y): myaxes = fig.gca() myaxes.plot(x,y) myaxes.set_title('Test') if __name__ == '__main__': import pylab from scipy import arange, pi, sin t=arange(0,1,0.01) y=sin(2*pi*t) myfig = pylab.figure() myplot(myfig,t,y) pylab.draw() pylab.show() import wxmpl # Create the PlotApp instance. # The title string is one of several optional arguments. app = wxmpl.PlotApp('WxMpl Example 1') from matplotlib.numerix import arange, pi, sin x = arange(0.0, 1, 0.01) y = sin(2*pi*x) ### Plot it ### # All of WxMpl's plotting classes have a get_figure(), # which returns the associated matplotlib Figure. fig = app.get_figure() import test_plot test_plot.myplot(fig, x, y) # == This spot is where the plotting happens # Let wxPython do its thing. app.MainLoop() - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users