Re: [Matplotlib-users] Setting linestyle of contours with negative values problem
Works for me. Thanks, Mark On 6/11/07, Eric Firing <[EMAIL PROTECTED]> wrote: Mark, Presumably the mailing list method worked at one time, but it would be obscure and unintuitive even if it worked now. There are no other explicit dash styles given as a pair of numbers in the rc file, so the change I made in svn is to use the strings "solid" and "dashed"; the two-float specification is deprecated. Eric Mark Bakker wrote: > Hello - > > I tried to turn of the feature that makes contours with negative values > dashed. > According to the mailinglist this should go by setting: > rcParams['contour.negative_linestyle']=('None','None') > I tried any combination of the None, None syntax, or just 'solid', but > nothing worked. > Example shown below. I am using 0.90.1. > Thanks, Mark > > from pylab import * > x,y = meshgrid(linspace(-3,3,10),linspace(-3,3,10)) > rcParams['contour.negative_linestyle']=('None','None') > contour(x,y,x,colors='b') > > Error message: > > Traceback (most recent call last): > File "", line 1, in ? > contour(x,y,x,colors='b') > File "C:\Python24\Lib\site-packages\matplotlib\pylab.py", line 1777, > in contour > draw_if_interactive() > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 59, in draw_if_interactive > figManager.show() > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 311, in show > self.canvas.draw() > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 154, in draw > FigureCanvasAgg.draw(self) > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line > 392, in draw > self.figure.draw(renderer) > File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 601, > in draw > for a in self.axes: a.draw(renderer) > File "C:\Python24\Lib\site-packages\matplotlib\axes.py", line 1286, in > draw > a.draw(renderer) > File "C:\Python24\Lib\site-packages\matplotlib\collections.py", line > 700, in draw > transoffset) > ValueError: invalid literal for float(): None > > > > > - > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > > > > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] to build barbs in quiver resultant vector
nappie74 wrote: > Hi, > I'm new in matplolib code, > I have matrix of winds vectors Hi, thanks, yes infact wind barbs it's difficult to plot with quiver I have to coding something appropiate. So ,just I HAVE FOR THE MOMENT TO PLOT ONLY A LEGEND with one wind vector that have a lenght autoscaled like quiver: this vector is for example 5 m/s and for the other vectors everyone can make an idea of intensity. the legend facilty make this or is there an other way in quiver commands. --Pie -- View this message in context: http://www.nabble.com/to-build-barbs-in-quiver-resultant-vector-tf3889736.html#a11056084 Sent from the matplotlib - users mailing list archive at Nabble.com. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mouse events, get data and disconnect
Hello darkside, the below example seems to do the job. The problem with x, y = event.xdata, event.ydata could be due to a local-global-variable issue (solution: define x, y with keyword global, i.e. "global x, y" in your function 'click' [ -> they become global variables] to change their values in this function and use them in the main program, too). best regards, Matthias >-- import pylab from matplotlib.widgets import Cursor datax=[] datay =[] def click(event): if event.button == 1: if event.inaxes: print 'data coords: ', event.xdata, event.ydata datax.append(event.xdata) datay.append(event.ydata) # disconnect the connection with id 'cid' after the first run of # this part pylab.disconnect(cid) if event.button == 3: # only possible before the first run of the upper # part ' if event.button == 1' pylab.close() return datax,datay fig = pylab.figure(figsize=(8,6)) ax = fig.add_subplot(111) ax.plot(pylab.arange(10)) cursor = Cursor(ax, useblit=False, color='red', linewidth=2) cursor.horizOn = False # connection with id 'cid' cid = pylab.connect('button_press_event', click) pylab.show() print 'los arrays de data son: ', datax,datay >- On Sunday 10 June 2007 04:54, darkside wrote: > Hello, > I've tried your idea, but it doesn't work. > If I put: > -- > datax=[] > datay =[] > > > def click(event): > > if event.button == 1: > if event.inaxes: > print 'data coords: ', event.xdata, event.ydata > datax.append(event.xdata) > datay.append(event.ydata) > pylab.disconnect(click) > > if event.button == 3: > pylab.close() > > return datax,datay > > fig = pylab.figure(figsize=(8,6)) > ax = fig.add_subplot(111) > ax.plot(pylab.arange(10)) > cursor = Cursor(ax, useblit=False, color='red', linewidth=2) > cursor.horizOn = False > > pylab.connect('button_press_event', click) > > pylab.show() > print 'los arrays de data son: ', datax,datay > > It returns the arrays, but it doesn't stop after one click, I have to press > number 3 to exit. > > I tried to change to x, y instead of datax, datay in the following way: > > > x, y = 0,0 > > x, y = event.x, event.y > - > > But in this case I get an error: "name 'x' is not defined" > And I don't know why, because I only change the lines refering to datax, > datay. It seems that only works with lists, but I don't know if this is the > problem exactly. > > With the command close, I can close the figure window pressing right mouse > button. It works (at least something works). > > Thank you for your help. > > 2007/6/4, Matthias Michler <[EMAIL PROTECTED]>: > > Hello darkside, > > > > maybe the following little examples helps you with disconnecting: > > > > > > > > > > from pylab import * > > > > def event_response(event): > > print event.name > > disconnect(cid) > > > > subplot(111) > > cid = connect('button_press_event', event_response) > > > > show() > > > > > > > >- > > > > concerning opening of figures: > > I think it is not possible to open a figure after the show() > > ( I asked some time ago with subject "open / close or set active figures > > during mainloop", but unfortunately without response). > > > > Maybe it would be sufficient for you to clean the figure or the axes > > (pylab.clf/cla), resetting labels and use the same connected event > > several times. > > > > best regards, > > Matthias > > > > On Monday 04 June 2007 04:28, darkside wrote: > > > I'm trying to use matplotlib to get an x point on some figures by > > > > mouse > > > > >clicking. > > >To do this I try the next example: > > >- > > >datax=[] > > >datay =[] > > >def click(event): > > >x, y = event.x, event.y > > >if event.button == 1: > > >if event.inaxes: > > >print 'data coords: ', event.xdata, event.ydata > > >datax.append(event.xdata) > > >datay.append(event.ydata) > > >if event.button == 3: > > >pylab.close() > > >return datax,datay > > >fig = pylab.figure(figsize=(8,6)) > > >ax = fig.add_subplot(111) > > > > > > - Ignored: > > >ax.plot(pylab.arange(10)) > > >cursor = Cursor(ax, useblit=False, color='red', linewidth=2) > > >cursor.horizOn = False > > > > > >pylab.connect('button_press_event', click) > > > > > >pylab.show() > > >pylab.disconnect(click) > > >prin
Re: [Matplotlib-users] to build barbs in quiver resultant vector
nappie74 wrote: > > > nappie74 wrote: >> Hi, >> I'm new in matplolib code, >> I have matrix of winds vectors > > Hi, thanks, yes infact wind barbs it's difficult to plot with quiver I have > to coding something appropiate. > So ,just I HAVE FOR THE MOMENT TO PLOT ONLY A LEGEND with one wind vector > that have a lenght autoscaled like quiver: this vector is for example 5 m/s > and for the other vectors everyone can make an idea of intensity. the legend > facilty make this or is there an other way in quiver commands. > --Pie > In the mpl examples directory look at quiver_demo.py, which illustrates the quiverkey function. Eric - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] contour & colorbar...
Hi, Please look at the short example attached showing the issue. I want to display only one contour line, with value 0.8. Obviously, the color associated with this contour line is bad (blue instead of red color). I think the reason is that the contour has its own colormap, so for only one value, the color is blue. I don't see anything about this issue in the contour help. How can I fix this ? Thanks in advance. Cheers, -- http://scipy.org/FredericPetit #! /usr/bin/env python from scipy import * from pylab import * x, y = ogrid[-3:3:10*1j,-3:3:10*1j] a = cos(x)*sin(y) imshow(a) colorbar() contour(a, [0.8]) show() - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Simple scatter plot over an image
On 6/10/07, __ <[EMAIL PROTECTED]> wrote: > Hello, > > I'm trying to plot a simple list of x/y coords over an image (.png). I can > show the image, or plot the data, but cannot find a way to layer one over > the other. I would greatly appreciate someone pointing me in the right Just call imshow and set the "extent" kwarg to let mpl know about the coordinates of the image, and then call scatter. See examples/image_demo2.py in the mpl src distribution, ot at http://matplotlib.sourceforge.net/examples/image_demo2.py JDH - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Simple scatter plot over an image
Excellent. Thank you very much! On 6/10/07, Jake Emerson <[EMAIL PROTECTED]> wrote: The python imaging library is pretty good for this kind of thing. http://www.pythonware.com/library/pil/handbook/ Here's an (untested) example. Hope it helps. Jake #!/usr/bin/env python from pylab import scatter, save import Image #get the background image, and find out how big it is im_bg = Image.open("background.png") bg_width, bg_height = im.size #make a white canvas on which to paste the background image and the scatter plot #this will allow you to, say, have the x- and y-axis values fall outside of the background image's limits im_canvas = Image.new("RGBA", (bg_width+60, bg_height+60), (255, 255, 255, 0)) #create the scatter plot from x and y data with matplotlib scatter(x, y, s=sizes, alpha=0.75) #save the scatter plot, and then retrieve it for use in PIL, convert to RGBA so that alpha levels will work #there is probably a better way to do this with gcf() or gci()... savefig("scatter_plot.png") im_scatter = Image.open("scatter_plot.png").convert("RGBA") #resize the scatter image to make it fit nice im_scatter.resize((bg_width+10, bg_height+10)) #bring all of the images together by pasting them onto the white canvas, use the overlayed image as the mask (third element) im_canvas.paste(im_bg, (30, 30), im_bg) #play around with the paste locations (30, 30) im_canvas.paste(im_scatter, (10, 30), im_scatter) #these won't be perfect the first time (10, 30) #save it im_canvas.save("combo_image.png") -- *From:* __ [mailto:[EMAIL PROTECTED] *Sent:* Sunday, June 10, 2007 5:22 PM *To:* matplotlib-users@lists.sourceforge.net *Subject:* [Matplotlib-users] Simple scatter plot over an image Hello, I'm trying to plot a simple list of x/y coords over an image (.png). I can show the image, or plot the data, but cannot find a way to layer one over the other. I would greatly appreciate someone pointing me in the right direction. Thanks. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] out of curiosity...
Coming from MATLAB, I started using matplotlib in the same fashion (and was very appreciative of the similariry). That is, I would import pylab and call the plotting functions as necessary. However, after seeing some of how others are using matplotlib, it seems most people use axes object methods to take care of plotting needs. I'm now taking this approach as well, but I honestly don't know why I should (or if I should). Will someone explain to me why one approach is better or worse? thanks, trevis Trevis Crane Postdoctoral Research Assoc. Department of Physics University of Ilinois 1110 W. Green St. Urbana, IL 61801 p: 217-244-8652 f: 217-244-2278 e: [EMAIL PROTECTED] - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] out of curiosity...
On 6/11/07, Trevis Crane <[EMAIL PROTECTED]> wrote: > Coming from MATLAB, I started using matplotlib in the same fashion (and was > very appreciative of the similariry). That is, I would import pylab and > call the plotting functions as necessary. However, after seeing some of how > others are using matplotlib, it seems most people use axes object methods to > take care of plotting needs. I'm now taking this approach as well, but I > honestly don't know why I should (or if I should). Will someone explain to > me why one approach is better or worse? matplotlib supports both because in different contexts one is often superior to the other. The main difference is that the pylab interface is stateful and handles object instantiation when necessary. For example, when you do "plot", it checks to see if there is a current axes and if so plots into it, and if not creates a new axes. When the new axes function is called, it checks to see if there is a current figure and inserts into it if available, and if not creates one. So it is "stateful" because under the hood it is tracking the current axes, figure and some other stuff. When working interactively from the shell or in short scripts, this is a nice feature because it saves typing and syntactic overhead. When working in the shell, eg in ipython -pyab mode, this is usually the way I work. In other contexts the convenience that these functions imply become a liability, because you often want to have explicit control, eg "put this axes in this figure and put this plot into this axes...". In a web application server or a user interface application, this is definitely the way to work. In scripts of moderate complexity it is advisable. The basic idea is that "explicit is better than implicit". Working this way is a little harder at first, but by forcing yourself to understand who is doing what where, you ultimately write better, more stable, more maintainable code. One thing most serious python programmers agree on is that from something import * is bad practice because you usually don't know what names are coming from where, and it creates the possibility of latent bugs. Eg, pylab used to have a "set" command which emulates the matlab command of the same name. It is used to set handle graphics properties. This worked fine, until python introduced the "set" builtin, which works like the mathematical set. Then it became impossible do "from pylab import *" and use the new python builtin "set", so we cleaned up all the old code and renamed the function. The programmer who do import pylab pylab.set was protected from these often subtle and difficult to detect bugs. The import * idiom also makes it tricky to combine code from two scripts or modules into one, because both may be importing different namespaces with overlapping names. I have found, however, when talking to science teachers who are trying to introduce python/numpy/pylab/scipy into the classroom as a matlab replacement that the 'from pylab import *' idiom is important to them, because their students want something that "just works" and is about as easy as matlab. Even though it is probably preferable in the abstract to teach students good practices from the beginning, it might raise the barrier to entry sufficiently that they simply use matlab instead. These teachers are already facing a fair amount of resistance in trying to get python introduced at all, and we should make it as easy on them as possible. So I am not a zealot on this issue. The other reason it is good practice to use the explicit API calls is that code which starts out its life as a small script often has a way of growing into a large script, and then you begin sharing it with your colleagues and maybe writing a web interface or a GUI application built on it. Code written using the API can safely be dropped into larger applications, whereas code written in pylab probably cannot (imagine lots of different functions competing for the current figure w/o knowledge of one another). So the answer of which is better is a question of skill level and context, but my simple advice is to use the pylab syntax from the interactive python shell (and "ipython -pylab" is ideal for this) and the API everywhere else. Most of my scripts are variants of this: import numpy as npy from pylab import figure, close, show fig = figure() ax = fig.add_subplot(111) x = npy.arange(0,10.) ax.plot(x) show() JDH - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] out of curiosity...
> -Original Message- > From: John Hunter [mailto:[EMAIL PROTECTED] > Sent: Monday, June 11, 2007 9:08 AM > To: Trevis Crane > Cc: matplotlib-users@lists.sourceforge.net > Subject: Re: [Matplotlib-users] out of curiosity... > > On 6/11/07, Trevis Crane <[EMAIL PROTECTED]> wrote: > > > Coming from MATLAB, I started using matplotlib in the same fashion (and was > > very appreciative of the similariry). That is, I would import pylab and > > call the plotting functions as necessary. However, after seeing some of how > > others are using matplotlib, it seems most people use axes object methods to > > take care of plotting needs. I'm now taking this approach as well, but I > > honestly don't know why I should (or if I should). Will someone explain to > > me why one approach is better or worse? > [Trevis Crane] John, your explanation is great. Thanks for taking the time. trevis > matplotlib supports both because in different contexts one is often > superior to the other. > > The main difference is that the pylab interface is stateful and > handles object instantiation when necessary. For example, when you do > "plot", it checks to see if there is a current axes and if so plots > into it, and if not creates a new axes. When the new axes function is > called, it checks to see if there is a current figure and inserts into > it if available, and if not creates one. So it is "stateful" because > under the hood it is tracking the current axes, figure and some other > stuff. > > When working interactively from the shell or in short scripts, this is > a nice feature because it saves typing and syntactic overhead. When > working in the shell, eg in ipython -pyab mode, this is usually the > way I work. > > In other contexts the convenience that these functions imply become a > liability, because you often want to have explicit control, eg "put > this axes in this figure and put this plot into this axes...". In a > web application server or a user interface application, this is > definitely the way to work. In scripts of moderate complexity it is > advisable. > > The basic idea is that "explicit is better than implicit". Working > this way is a little harder at first, but by forcing yourself to > understand who is doing what where, you ultimately write better, more > stable, more maintainable code. > > One thing most serious python programmers agree on is that > > from something import * > > is bad practice because you usually don't know what names are coming > from where, and it creates the possibility of latent bugs. Eg, pylab > used to have a "set" command which emulates the matlab command of the > same name. It is used to set handle graphics properties. This worked > fine, until python introduced the "set" builtin, which works like the > mathematical set. Then it became impossible do "from pylab import *" > and use the new python builtin "set", so we cleaned up all the old > code and renamed the function. The programmer who do > > import pylab > pylab.set > > was protected from these often subtle and difficult to detect bugs. > > The import * idiom also makes it tricky to combine code from two > scripts or modules into one, because both may be importing different > namespaces with overlapping names. > > I have found, however, when talking to science teachers who are trying > to introduce python/numpy/pylab/scipy into the classroom as a matlab > replacement that the 'from pylab import *' idiom is important to them, > because their students want something that "just works" and is about > as easy as matlab. Even though it is probably preferable in the > abstract to teach students good practices from the beginning, it might > raise the barrier to entry sufficiently that they simply use matlab > instead. These teachers are already facing a fair amount of > resistance in trying to get python introduced at all, and we should > make it as easy on them as possible. So I am not a zealot on this > issue. > > The other reason it is good practice to use the explicit API calls is > that code which starts out its life as a small script often has a way > of growing into a large script, and then you begin sharing it with > your colleagues and maybe writing a web interface or a GUI application > built on it. Code written using the API can safely be dropped into > larger applications, whereas code written in pylab probably cannot > (imagine lots of different functions competing for the current figure > w/o knowledge of one another). > > So the answer of which is better is a question of skill level and > context, but my simple advice is to use the pylab syntax from the > interactive python shell (and "ipython -pylab" is ideal for this) and > the API everywhere else. Most of my scripts are variants of this: > > import numpy as npy > from pylab import figure, close, show > fig = figure() > ax = fig.add_subplot(111) > x = npy.arange(0,10.) > ax.plot(x) > show() > > JDH ---
[Matplotlib-users] Twinx and semilogy - how to move axes relative to one another
Sorry for the repost, but I'm still struggling with this. I'm trying to replicate a plot like this: http://tinyurl.com/2uwjn8 In this case, the y-axis on the left (the black dots) is linear and the y-axis on the right (red data) is log base 2. I can't figure out how to do the following: 1. How do I display the right-hand y-axis so that is includes the range above 32 and below 0 (as in the linked figure)? When I try to include 0 or below in the axis range, I get a range error (because of the log function). When I do auto-range, it ranges from 2 to 32. But I want to include 0 (and below) in my figure. 2. How do I line up the centers of both axes. in this case, the y-axis on the left needs to have the 0 value lined up with the value of 2 on the y axis on the right. In other words, how to I move one y-axis relative to the other. This is the best I can do so far. http://tinyurl.com/yotf2b As you can see, I can't get the right axis as log2 and still keep the 0 values. I'd really like to have a log axis on the right, because some of those values (red) are quite high. Thanks for the advice. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] (no subject)
Hello everyone! I'm seeking help with real-time plotting using Python and MatPlotLib. I've encoutered several problems so far: 1. There is no function to just add a point to the existing curve, so each time the data is updated all the curve has to be redrawn. This is not a clean solution for the real-time plotting. 2. I'm trying to use threads in Python in order to be able to get the data and draw the curve at the same time. Sometimes it's working, and sometimes the graphics rendering just hangs. Moreover, if I try to use the Timer class for the plotting thread, it is invoked only one time. I wonder, if my threads are stirring with a graphical library ones. If there is no special thread handling with Tk, I'll investigate my code again. I'll appreciate any help. Thank you. Dendron. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Real-time plotting
Hello everyone! I'm seeking help with real-time plotting using Python and MatPlotLib. I've encoutered several problems so far: 1. There is no function to just add a point to the existing curve, so each time the data is updated all the curve has to be redrawn. This is not a clean solution for the real-time plotting. 2. I'm trying to use threads in Python in order to be able to get the data and draw the curve at the same time. Sometimes it's working, and sometimes the graphics rendering just hangs. Moreover, if I try to use the Timer class for the plotting thread, it is invoked only one time. I wonder, if my threads are stirring with a graphical library ones. If there is no special thread handling with Tk, I'll investigate my code again. I'll appreciate any help. Thank you. Dendron. P.S.: Sorry, forgot to put a title in the previous post. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] out of curiosity...
* John Hunter <[EMAIL PROTECTED]> [070611 16:20]: > So the answer of which is better is a question of skill level and > context, but my simple advice is to use the pylab syntax from the > interactive python shell (and "ipython -pylab" is ideal for this) and > the API everywhere else. Most of my scripts are variants of this: > > import numpy as npy > from pylab import figure, close, show > fig = figure() > ax = fig.add_subplot(111) > x = npy.arange(0,10.) > ax.plot(x) > show() Hello, is there also a (possible object oriented) way to show/print a given figure? Like fig.show() or fig.print_figure(). I need it because I have a script generating (returning) several plots, and the user should be able to print/show the plots he likes. At the moment I use: ipython -pylab from myscript import plotgenerator fig = plotgenerator() canvas = get_current_fig_manager().canvas canvas.figure = fig canvas.print_figure('myplot.png') Here plotgenerator does something like: from matplotlib.figure import Figure fig = Figure() ax = myplot.add_subplot(111) ax.plot(x) But its cumbersome, and canvas.show() doesn not work (it gives an exception). Best would be if fig.show() (popping up a new canvas) and fig.print_figure() worked. Best Regards, Roman - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] issues with interacting with a plot
Hi, I've coded (with help from John) a plot of mine to allow a user to select a data point, and when they click on it a new plot pops up. It works great. However, some of the points are very close together and if I'm not extremely careful in selecting the point, then multiple graphs pop up or I get the wrong one entirely. So, I figured maybe if I zoomed in then it'd be easier to select the desired point. The problem is that after zooming/panning, the mouse cursor changes and my click events are no longer recognized as such. Furthermore, I can't find a way to make the mouse cursor return to its normal state and allow me to continue clicking events. Is there something I'm missing? thanks, trevis Trevis Crane Postdoctoral Research Assoc. Department of Physics University of Ilinois 1110 W. Green St. Urbana, IL 61801 p: 217-244-8652 f: 217-244-2278 e: [EMAIL PROTECTED] - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] issues with interacting with a plot
Hi Trevis, On 12/06/07, Trevis Crane <[EMAIL PROTECTED]> wrote: > So, I figured maybe if I zoomed in then it'd be easier to select the desired > point. The problem is that after zooming/panning, the mouse cursor changes > and my click events are no longer recognized as such. Furthermore, I can't > find a way to make the mouse cursor return to its normal state and allow me > to continue clicking events. Is there something I'm missing? Could it be that you're still in zoom or pan mode when you try to click to select a point? You'll see the zoom or pan button highlighted in the toolbar if that is the case. Clicks when in these modes don't activate the callback feature, so you need to click again on the same toolbar button to leave that mode; then the cursor should return to an arrow and your callback routine should be activated correctly. HTH, A. -- AJC McMorland, PhD Student Physiology, University of Auckland - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] date-gaps in timeseries
try using plot_date() function instead of plot() On Sun, 2007-06-10 at 09:49 +0200, rolandreichel wrote: > Hi, > > I want to plot some timeseries (eg. stockcharts). I use now > DateLocator/Formatter, it works fine for me with the exeption, that > dataless periods on X-Axis (eg. weekends) are also plotted. Is there an > easy way to suppress them? > > regards > > - > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] issues with interacting with a plot
> > Hi Trevis, > > > > On 12/06/07, Trevis Crane <[EMAIL PROTECTED]> wrote: > > So, I figured maybe if I zoomed in then it'd be easier to select the desired > > point. The problem is that after zooming/panning, the mouse cursor changes > > and my click events are no longer recognized as such. Furthermore, I can't > > find a way to make the mouse cursor return to its normal state and allow me > > to continue clicking events. Is there something I'm missing? > > Could it be that you're still in zoom or pan mode when you try to > click to select a point? You'll see the zoom or pan button highlighted > in the toolbar if that is the case. Clicks when in these modes don't > activate the callback feature, so you need to click again on the same > toolbar button to leave that mode; then the cursor should return to an > arrow and your callback routine should be activated correctly. [Trevis Crane] I feel like a bonehead sometimes. That helps. I didn't know to click the button again to get out of pan/zoom mode. thanks, trevis > HTH, > > A. > -- > AJC McMorland, PhD Student > Physiology, University of Auckland > > - > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] issues with interacting with a plot
On 6/11/07, Trevis Crane <[EMAIL PROTECTED]> wrote: I've coded (with help from John) a plot of mine to allow a user to select a data point, and when they click on it a new plot pops up. It works great. However, some of the points are very close together and if I'm not extremely careful in selecting the point, then multiple graphs pop up or I get the wrong one entirely. You can always write a custom hit testing function -- see http://matplotlib.sourceforge.net/examples/pick_event_demo.py for an example. Probably easiest here is to just find the index which is closest to one of your data points and just plot that data set. BTW, numpy gurus, is there a better way to find the index in an array that is minimal than indmin = int(numpy.nonzero(distances.min()==distances)[0]) import numpy from pylab import figure, show X = numpy.random.rand(100, 200) xs = numpy.mean(X, axis=1) ys = numpy.std(X, axis=1) fig = figure() ax = fig.add_subplot(211) ax.set_title('click on point to plot time series') line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance ax2 = fig.add_subplot(212) def onpick(event): if event.artist!=line: return True N = len(event.ind) if not N: return True # the click locations x = event.mouseevent.xdata y = event.mouseevent.ydata distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. + (y-ys[event.ind])**2)) indmin = int(numpy.nonzero(distances.min()==distances)[0]) dataind = event.ind[indmin] print event.ind, distances, indmin, dataind, X[dataind][:5] ax2.cla() ax2.plot(X[dataind]) ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), transform=ax2.transAxes, va='top') ax2.set_ylim(-0.5, 1.5) fig.canvas.draw() return True fig.canvas.mpl_connect('pick_event', onpick) show() """ compute the mean and stddev of 100 data sets and plot mean vs stddev. When you click on one of the mu, sigma points, plot the raw data from the dataset that generated the mean and stddev """ import numpy from pylab import figure, show X = numpy.random.rand(100, 200) xs = numpy.mean(X, axis=1) ys = numpy.std(X, axis=1) fig = figure() ax = fig.add_subplot(211) ax.set_title('click on point to plot time series') line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance ax2 = fig.add_subplot(212) def onpick(event): if event.artist!=line: return True N = len(event.ind) if not N: return True # the click locations x = event.mouseevent.xdata y = event.mouseevent.ydata distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. + (y-ys[event.ind])**2)) indmin = int(numpy.nonzero(distances.min()==distances)[0]) dataind = event.ind[indmin] print event.ind, distances, indmin, dataind, X[dataind][:5] ax2.cla() ax2.plot(X[dataind]) ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), transform=ax2.transAxes, va='top') ax2.set_ylim(-0.5, 1.5) fig.canvas.draw() return True fig.canvas.mpl_connect('pick_event', onpick) show() - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] date-gaps in timeseries
On 6/10/07, rolandreichel <[EMAIL PROTECTED]> wrote: > I want to plot some timeseries (eg. stockcharts). I use now > DateLocator/Formatter, it works fine for me with the exeption, that > dataless periods on X-Axis (eg. weekends) are also plotted. Is there an > easy way to suppress them? Plot numpy.arange(len(xdata)) vs y and use a custom tick locator to format the integer index to date strings. Some of the code below is using svn (eg the csv2rec stuff) but the core logic of formatting date strings from integers works with any reasonably current mpl. # plot dates evenly spaced, eg skipping weekends import numpy from matplotlib.mlab import csv2rec from pylab import figure, show from matplotlib.dates import Formatter r = csv2rec('data/msft.csv')[-40:] class MyFormatter(Formatter): def __init__(self, dates, fmt='%Y-%m-%d'): self.dates = dates self.fmt = fmt def __call__(self, x, pos=0): 'Return the label for time x at position pos' ind = int(round(x)) if ind>=len(self.dates) or ind<=0: return '' return self.dates[ind].strftime(self.fmt) formatter = MyFormatter(r.date) fig = figure() ax = fig.add_subplot(111) ax.xaxis.set_major_formatter(formatter) ax.plot(numpy.arange(len(r)), r.close, 'o-') fig.autofmt_xdate() show() - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] issues with interacting with a plot
John Hunter wrote: > BTW, numpy gurus, is there a better way to find the index in an array > that is minimal than > > indmin = int(numpy.nonzero(distances.min()==distances)[0]) yes -- see below. Also a few tweaks: >distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. + > (y-ys[event.ind])**2)) No need to call numpy.array on that, you're making a copy of what must be an array already. By the way, if you're not sure if it's an array, then you can use numpy.asarray(a) which won't make a copy if the argument is already an array. You can also use numpy.hypot() rather than explicitly calling sqrt(SumOfSquares): distances = numpy.hypot(x-xs[event.ind], y-ys[event.ind] ) (untested) or, if all you want is the closest one, you don't need to take the sqrt() at all: distances = ( (x-xs[event.ind])**2 + (y-ys[event.ind])**2 ) And don't use "2." in an exponent -- I think there is some optimization for integer exponents. >indmin = int(numpy.nonzero(distances.min()==distances)[0]) here you can use argmin: indmin = numpy.argmin(distances) of course, what you'd really want is a spatial index All untested -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(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 DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users