Re: [Matplotlib-users] imshow, matshow coordinate system
Richard, I have made the requested change to imshow, so it is consistent with the new matshow, and I think it makes much more sense this way--but note that it depends on your rc value for image.origin. So, whenever you get mpl from svn, or the next release (whenever that occurs--not very soon, I suspect), I think you will find both matshow and imshow more to your liking. I also changed the docstring explanation for the extent kwarg, noting that it gives (left, right, bottom, top) data limits of the axes. More doc changes and other tweaks for this class of functions will be in order, when I get back to it. Eric Richard Brown wrote: > On 22/03/07, Eric Firing <[EMAIL PROTECTED]> wrote: >> Richard Brown wrote: >> > Hi there, >> > >> > I'm pretty new to python; I'm in the process of switching from Matlab. >> > I do quite a bit of image processing in my research, and while >> > pylab/matplotlib seems to be a great plotting library, some of the >> > quirks seem just a little bit frustrating - I'm hoping for some >> > enlightenment :) >> > >> > When I use imshow or matshow to display an array, the points with >> > index (m, n) are displayed with the pixels centred at (0.5 + m, 0.5 + >> > n). Is there a setting somewhere to make it so that the centres of the >> > pixels are at the index values rather than their bottom left corners? >> > Or must I be always adding 0.5 to things to make them appear in the >> > right places? >> >> Coincidentally, a few days ago I made this change for matshow; I had >> made it in spy some time ago. I have so far left imshow alone; isn't >> its present behavior consistent with Matlab? That is not necessarily a >> good reason for leaving it the way it is, but it is reason for some >> caution. I suspect quite a few people may prefer it the way it is; >> let's see who responds, and what opinions are voiced. > > Thanks for your timely response. Let me give you a few examples to > clarify the things which I think might be relevant issues to address. > (numpy and pylab imported) > > PRELIMINARIES > # Create a 6x6 logical array with a 2x2 square near the to left > xx = zeros((6, 6), dtype='Bool') > xx[1:3, 1:3] = True > > > EXAMPLE 1 - imshow > Trying to plot a point which should appear on the square: imshow(xx, interpolation='nearest') plot([2],[2], 'y.', markersize=20) > > The image looks correct, with the square in the top left, but the y > axis is labelled backwards. Therefore when I try to plot a point in > the middle of it, it misses altogether > > EXAMPLE 2 - matshow (not your new version) matshow(xx) > So far so good - the y axis is the right way around plot([2],[2], 'y.', markersize=20) > Oops - the y axis flipped, there is a block of white at the top, and > the image is now upside-down. The point has showed up in the right > place w.r.t the image though. > > EXAMPLE 3 - off by 0.5 problem - relevant to imshow too matshow(xx) > Let's say I want to compute the centroid of the square blob. IMO a > natural way to do this is: cen = mean(where(xx), 1) plot([cen[0]], [cen[1]], 'y.') > > This is off by 0.5 in both directions. This kind of thing is my > argument for why the coordinate system should be aligned with the > array indices. > > Matlab behaviour: > In Matlab, the pixels are centred on integer coordinates corresponding > to their array index. Matlab indexing is ones based, so a 2x2 image > will have axes limits of 0.5-2.5 in each direction, with the pixel > centres at (1,1), (1,2) etc. > imshow in Matlab plots the array with the (1,1) coordinate in the top > left, and the y axis increasing from the top down (like what matshow > does here) > > cheers, > > Richard - 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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] reversing an axis
Hi, I'm wondering if there's an easy way to reverse an axis in a plot. For instance, suppose I wanted to create a plot that had its "origin" in the upper left hand corner, so that x would range from, say 0 to 1 moving right, and y would range from, say 0 to 1, moving down. Thanks! --b - 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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] reversing an axis
belinda thom wrote: > Hi, > > I'm wondering if there's an easy way to reverse an axis in a plot. Using methods: bottom, top = ax.get_ylim() ax.set_ylim(top, bottom) Or using pylab functions: bottom, top = ylim() ylim(top, bottom) Eric > > For instance, suppose I wanted to create a plot that had its "origin" > in the upper left hand corner, so that x would range from, say 0 to 1 > moving right, and y would range from, say 0 to 1, moving down. > > Thanks! > > --b > > > - > 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.php&p=sourceforge&CID=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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] reversing an axis
Eric, This is great; much thanks! --b On Mar 23, 2007, at 3:16 PM, Eric Firing wrote: > belinda thom wrote: >> Hi, >> I'm wondering if there's an easy way to reverse an axis in a plot. > > Using methods: > > bottom, top = ax.get_ylim() > ax.set_ylim(top, bottom) > > Or using pylab functions: > > bottom, top = ylim() > ylim(top, bottom) > > Eric > >> For instance, suppose I wanted to create a plot that had its >> "origin" in the upper left hand corner, so that x would range >> from, say 0 to 1 moving right, and y would range from, say 0 to >> 1, moving down. >> Thanks! >> --b >> - >> >> 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.php&p=sourceforge&CID=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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] passing mouse clicks back to a polling application
Hi, I'm trying to write a very simple GUI using matplotlib and have gotten stuck. Hopefully someone out there has done something similar and can point me on my way. First, I should mention that the examples provided with matplotlib weren't immediately helpful to me, because when I try to run various demos (like pick_event_demo or object_picker) it fails b/c I'm relying on (and have to rely on) TkAgg. Sadly, I'm too new to understand what I would need to do to get those demos working. So I found someone processing mouseclicks using a Mac online and started there. I ended up with something like this: from pylab import * class gui : def __init__(self) : self.f = figure() self.data = None # valid mouse click hasn't yet happened def clicker(event): self.data = event.xdata self.f.canvas.mpl_connect("button_press_event",clicker) def getNextValidClick(self) : (data, self.data) = (None, None) while True : print "Waiting for valid mouse click..." while self.data == None : pass # keep polling if 1 <= self.data <= 3 : # consider this a valid next mouse click (data, self.data) = (self.data, None) break return data With which I tried: g = gui() x = g.getNextValidClick() but the latter line caused me to experience the spinning wheel of dead that we mac users so enjoy. I have the feeling I need to explicitly yield or some such in the poll loop, but I don't know how to do that. Advice greatly appreciated, both on the code I've provided, and on if there is a better way altogether to provide an app with data obtained via a matplotlib mouse click callback. Thanks, --b - 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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] passing mouse clicks back to a polling application
On 24/03/07, belinda thom <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to write a very simple GUI using matplotlib and have > gotten stuck. Hopefully someone out there has done something similar > and can point me on my way. > > First, I should mention that the examples provided with matplotlib > weren't immediately helpful to me, because when I try to run various > demos (like pick_event_demo or object_picker) it fails b/c I'm > relying on (and have to rely on) TkAgg. Sadly, I'm too new to > understand what I would need to do to get those demos working. So I > found someone processing mouseclicks using a Mac online and started > there. > > I ended up with something like this: > >from pylab import * >class gui : > def __init__(self) : > self.f = figure() > self.data = None # valid mouse click hasn't yet happened > def clicker(event): > self.data = event.xdata > self.f.canvas.mpl_connect("button_press_event",clicker) > > def getNextValidClick(self) : > (data, self.data) = (None, None) > while True : > print "Waiting for valid mouse click..." > while self.data == None : > pass # keep polling > if 1 <= self.data <= 3 : > # consider this a valid next mouse click > (data, self.data) = (self.data, None) > break > return data > > With which I tried: > > g = gui() > x = g.getNextValidClick() > > but the latter line caused me to experience the spinning wheel of > dead that we mac users so enjoy. > > I have the feeling I need to explicitly yield or some such in the > poll loop, but I don't know how to do that. > > Advice greatly appreciated, both on the code I've provided, and on if > there is a better way altogether to provide an app with data obtained > via a matplotlib mouse click callback. > > Thanks, > > --b It's the polling that's the problem. Why not use a slightly different approach, like this: --- from pylab import figure class gui : def __init__(self, callback) : self.f = figure() self.ax = self.f.add_subplot(111) self.ax.plot([1,2,3]) self.data = None # valid mouse click hasn't yet happened def clicker(event): self.data = event.xdata if 1 <= self.data <= 3: callback(self.data) self.f.canvas.mpl_connect("button_press_event",clicker) print "Waiting for valid mouse click..." then in your application (or shell): def my_cb(inp): # processing here print inp g = gui(my_cb) No polling required, and you only get the valid clicks calling your routine. I hope that helps, A. -- AJC McMorland, PhD Student Physiology, University of Auckland - 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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Fwd: interactive plots again
gah! bitten by reply to sender once again. --bb -- Forwarded message -- From: Bill Baxter <[EMAIL PROTECTED]> Date: Mar 24, 2007 12:09 PM Subject: Re: [Matplotlib-users] interactive plots again To: Robert Cimrman <[EMAIL PROTECTED]> Are you sure that's threadsafe? With most windowing toolkits it's not safe to do GUI things from threads other than the main one. Other threads can only post a message to the main GUI thread. Depending on how fig.canvas.draw is implemented, calling it from another thread might not be kosher. But I take it you haven't seen any meltdowns so far, so maybe its implementation does the threadsafe message posting thing. --bb On 3/22/07, Robert Cimrman <[EMAIL PROTECTED]> wrote: > Maybe I have reinvented the wheel, but I find the attached code snippet > very useful. > I have modified a bit the recipe at > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65222 > to be used in the following situation: > > You plot (interactively) something in a main program, which than works > heavily. Normally, when the figure window gets obscured, it will not > redraw. The attached code shows how to make a thread that periodically > redraws the figure. > > r. > > - > 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.php&p=sourceforge&CID=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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Default Reply-to-sender
Did you guys make a conscious decision to have the matplotlib list send replies only to the sender of the message rather than the list? This seems to be the default at SourceForge, so it's conceivable you just haven't bothered to change it. I've been on at least 10 different mailing lists in the past 2 years or so, and of those matplotlib's is the only one I can recall being set up with default reply-to-sender rather than reply-to-list. I keep accidentally replying to senders only, so I thought I'd mention it. In the admin section on sourceforge there's a checkbox you can set to change the list from reply-to-sender to reply-to-list as the default. --bb - 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.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users