Re: [Matplotlib-users] offset in dragging a legend
On Thu, Mar 26, 2009 at 12:19 AM, Jae-Joon Lee wrote: > Sorry, It's hard to track down what's wrong without actually running the code. I really appreciate your patience. > Change > > self.legend._loc = loc_in_norm_axes > > to > > self.legend._loc = tuple(loc_in_norm_axes) > > and see if it works. > That did it! Thank you. > You need to call canvas.draw. However, it will draw whole figure > again. If you're concerned about speed, you may consider to use blit > method. > http://matplotlib.sourceforge.net/examples/animation/animation_blit_wx.html I'll look into it. For the time being, this is already a very good improvement. Thanks so much for the help. For the archives, the working runnable sample (if you have wxPython) is attached. Che draggable_legend2.py Description: Binary data -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Sorry, It's hard to track down what's wrong without actually running the code. Change self.legend._loc = loc_in_norm_axes to self.legend._loc = tuple(loc_in_norm_axes) and see if it works. You need to call canvas.draw. However, it will draw whole figure again. If you're concerned about speed, you may consider to use blit method. http://matplotlib.sourceforge.net/examples/animation/animation_blit_wx.html -JJ On Wed, Mar 25, 2009 at 10:55 PM, C M wrote: > On Wed, Mar 25, 2009 at 9:58 PM, Jae-Joon Lee wrote: >> Ah, my bad. >> >> Try >> >> self.legend.parent.transAxes.inverted().transform_point(loc_in_canvas) >> >> legend.parent points to the parent axes. >> >> -JJ >> > > That cleared up the error, thanks. But it is still not actually moving the > legend. The coordinates are changing as you described it: > > loc position (JJ method) = [ 0.89354419 0.91002415] > motion_event.x = 436 > motion_event.y = 349.0 > mouse moved x = 31 > mouse moved y = 3.0 > loc position (JJ method) = [ 0.90698505 0.91002415] > > but the legend doesn't move. > > I have tried to different ways of doing the draw method. > > 1. self.canvas.draw() > That gives this error and does not move the legend: > ValueError: The truth value of an array with more than one element is > ambiguous. Use a.any() or a.all() > > 2. self.draw() (this is a method which draws the lines and legend > originally in my class). > That just does nothing, though the output is as shown above. > > What do I have to do to actually show the repositioned legend? > > Thanks for your patience, > C > > -- > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
On Wed, Mar 25, 2009 at 9:58 PM, Jae-Joon Lee wrote: > Ah, my bad. > > Try > > self.legend.parent.transAxes.inverted().transform_point(loc_in_canvas) > > legend.parent points to the parent axes. > > -JJ > That cleared up the error, thanks. But it is still not actually moving the legend. The coordinates are changing as you described it: loc position (JJ method) = [ 0.89354419 0.91002415] motion_event.x = 436 motion_event.y = 349.0 mouse moved x = 31 mouse moved y = 3.0 loc position (JJ method) = [ 0.90698505 0.91002415] but the legend doesn't move. I have tried to different ways of doing the draw method. 1. self.canvas.draw() That gives this error and does not move the legend: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 2. self.draw() (this is a method which draws the lines and legend originally in my class). That just does nothing, though the output is as shown above. What do I have to do to actually show the repositioned legend? Thanks for your patience, C -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Ah, my bad. Try self.legend.parent.transAxes.inverted().transform_point(loc_in_canvas) legend.parent points to the parent axes. -JJ On Wed, Mar 25, 2009 at 9:36 PM, C M wrote: > On Wed, Mar 25, 2009 at 9:06 PM, Jae-Joon Lee wrote: >> As I said in my previous email, the _loc attribute of the legend need >> to be in the normalized axes coordinate, i.e., the lower left corner >> of the axes being (0,0) and the upper-right corner being (1,1). Thus, >> it needs to be something like below. >> >> loc_in_canvas = self.legend_x + mouse_diff_x, self.legend_y + mouse_diff_y >> loc_in_norm_axes = >> self.legend.transAxes.inverted().transform_point(loc_in_canvas) >> self.legend._loc = loc_in_norm_axes >> >> Note that it assumes that the parent of the legend is an Axes >> instance, which I think is your case. >> IHTH, >> >> -JJ > > Thanks, but I am getting this error now: > > AttributeError: 'Legend' object has no attribute 'transAxes' > > My legend is created this way: > > self.legend = self.subplot.legend(self.line_collections_list, ['1'], > numpoints=1) > > And self.subplot is made this way: > > self.figure = Figure(None, dpi) > self.subplot = self.figure.add_subplot(111) > > I thought self.subplot is an Axes instance. Is it not? > > Thank you, > C > > -- > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Working with arrows
You need to adjust the keyword arguments, such as head_width, etc. The arrow command itself is poorly documented and its keyword arguments are explained in matplitlib.patches.FancyArrow. However, I recommend you to use annotate command instead of arrow (you can give empty string if you just need an arrow). For example, annotate("", (0.2, 0.2), (0.4, 0.4), arrowprops=dict(arrowstyle="->")) more examples, http://matplotlib.sourceforge.net/examples/pylab_examples/annotation_demo.html http://matplotlib.sourceforge.net/examples/pylab_examples/annotation_demo2.html Annotate does not adjust the xlim and ylim of your axes for you, thus it is your responsibility. -JJ On Wed, Mar 25, 2009 at 6:39 PM, Sandro Tosi wrote: > Hello, > I'm trying to use arrows but I'm a little stuck. > > In [1]: import matplotlib > > In [2]: matplotlib.__version__ > Out[2]: '0.98.5.3' > > First, simply > > import matplotlib.pyplot as plt > plt.arrow(2,2,4,1) > > doesn't show anything, while at least a figure with an arrow in is > expected (or it's by design?) > > Secondly, with this simple script: > > import matplotlib.pyplot as plt > plt.plot(range(10)) > plt.arrow(2,2,4,1, linewidth=5) > plt.arrow(3,3,1,4) > > the result is quite ugly :) Where is the arrow pointer (for example)? > > I hope I'm missing something, but even in examples like "usetex_demo" > the arrows are drawn "by hand" :) > > Thanks, > -- > Sandro Tosi (aka morph, morpheus, matrixhasu) > My website: http://matrixhasu.altervista.org/ > Me at Debian: http://wiki.debian.org/SandroTosi > > -- > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
On Wed, Mar 25, 2009 at 9:06 PM, Jae-Joon Lee wrote: > As I said in my previous email, the _loc attribute of the legend need > to be in the normalized axes coordinate, i.e., the lower left corner > of the axes being (0,0) and the upper-right corner being (1,1). Thus, > it needs to be something like below. > > loc_in_canvas = self.legend_x + mouse_diff_x, self.legend_y + mouse_diff_y > loc_in_norm_axes = > self.legend.transAxes.inverted().transform_point(loc_in_canvas) > self.legend._loc = loc_in_norm_axes > > Note that it assumes that the parent of the legend is an Axes > instance, which I think is your case. > IHTH, > > -JJ Thanks, but I am getting this error now: AttributeError: 'Legend' object has no attribute 'transAxes' My legend is created this way: self.legend = self.subplot.legend(self.line_collections_list, ['1'], numpoints=1) And self.subplot is made this way: self.figure = Figure(None, dpi) self.subplot = self.figure.add_subplot(111) I thought self.subplot is an Axes instance. Is it not? Thank you, C -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Tony wrote a nice summary of the various coordinate system used in MPL, but it seems that it didn't make into the official documentation yet. Here is the link. This will give you some idea about the MPL's coordinate system. http://article.gmane.org/gmane.comp.python.matplotlib.general/14008 -JJ On Wed, Mar 25, 2009 at 9:06 PM, Jae-Joon Lee wrote: > As I said in my previous email, the _loc attribute of the legend need > to be in the normalized axes coordinate, i.e., the lower left corner > of the axes being (0,0) and the upper-right corner being (1,1). Thus, > it needs to be something like below. > > loc_in_canvas = self.legend_x + mouse_diff_x, self.legend_y + mouse_diff_y > loc_in_norm_axes = > self.legend.transAxes.inverted().transform_point(loc_in_canvas) > self.legend._loc = loc_in_norm_axes > > Note that it assumes that the parent of the legend is an Axes > instance, which I think is your case. > IHTH, > > -JJ > > > On Wed, Mar 25, 2009 at 8:26 PM, C M wrote: >> Ok, getting there. When I print the various coordinates to stdout, it >> SHOULD be working, but my legend is simply disappearing. This >> is the stdout on one pixel move with the mouse in the x: >> >> mouse x position at pick time 489 >> mouse y position at pick time 349.0 >> Legend x position at pick time = 445.878125 >> Legend y position at pick time= 339.8 >> motion_event.x = 488 >> motion_event.y = 349.0 >> mouse moved x = 1 >> mouse moved y = 0.0 >> new legend location on move = (446.8781249995, 339.81) >> release >> >> But what instead happens is the legend poofs out of existence. >> >> At the end of the motion event, I am calling this: >> >> self.canvas.draw() >> self.parent.Refresh() >> >> And wonder if I should be using some other way to redraw the legend? >> Is it just not being redrawn this way? I thought I should use self.draw(), >> which is a method in my class which draws the line and the legend, >> but using that does nothing at all. >> >> Very stuck here. Any help appreciated. >> C >> >> -- >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
As I said in my previous email, the _loc attribute of the legend need to be in the normalized axes coordinate, i.e., the lower left corner of the axes being (0,0) and the upper-right corner being (1,1). Thus, it needs to be something like below. loc_in_canvas = self.legend_x + mouse_diff_x, self.legend_y + mouse_diff_y loc_in_norm_axes = self.legend.transAxes.inverted().transform_point(loc_in_canvas) self.legend._loc = loc_in_norm_axes Note that it assumes that the parent of the legend is an Axes instance, which I think is your case. IHTH, -JJ On Wed, Mar 25, 2009 at 8:26 PM, C M wrote: > Ok, getting there. When I print the various coordinates to stdout, it > SHOULD be working, but my legend is simply disappearing. This > is the stdout on one pixel move with the mouse in the x: > > mouse x position at pick time 489 > mouse y position at pick time 349.0 > Legend x position at pick time = 445.878125 > Legend y position at pick time= 339.8 > motion_event.x = 488 > motion_event.y = 349.0 > mouse moved x = 1 > mouse moved y = 0.0 > new legend location on move = (446.8781249995, 339.81) > release > > But what instead happens is the legend poofs out of existence. > > At the end of the motion event, I am calling this: > > self.canvas.draw() > self.parent.Refresh() > > And wonder if I should be using some other way to redraw the legend? > Is it just not being redrawn this way? I thought I should use self.draw(), > which is a method in my class which draws the line and the legend, > but using that does nothing at all. > > Very stuck here. Any help appreciated. > C > > -- > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Ok, getting there. When I print the various coordinates to stdout, it SHOULD be working, but my legend is simply disappearing. This is the stdout on one pixel move with the mouse in the x: mouse x position at pick time 489 mouse y position at pick time 349.0 Legend x position at pick time = 445.878125 Legend y position at pick time= 339.8 motion_event.x = 488 motion_event.y = 349.0 mouse moved x = 1 mouse moved y = 0.0 new legend location on move = (446.8781249995, 339.81) release But what instead happens is the legend poofs out of existence. At the end of the motion event, I am calling this: self.canvas.draw() self.parent.Refresh() And wonder if I should be using some other way to redraw the legend? Is it just not being redrawn this way? I thought I should use self.draw(), which is a method in my class which draws the line and the legend, but using that does nothing at all. Very stuck here. Any help appreciated. C -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Running Python Script from PHP
Hello, I am trying to use the matplotlib to generate a histogram and display it on PHP / HTML. The following is the code: abc.py #!/usr/bin/python from pylab import randn, hist x = randn(1) hist(x, 100) testing_python.php www/New_HPD But still am unable to show it on the browser. Can anyone suggest a solution? Thanks-- Sudhir Chowbina Bioinformatics Graduate Student & Research Assistant Discovery Informatics and Computing Laboratory Indiana University School of Informatics Indianapolis, USA 317-847 7721 schow...@iupui.edu -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Working with arrows
Hello, I'm trying to use arrows but I'm a little stuck. In [1]: import matplotlib In [2]: matplotlib.__version__ Out[2]: '0.98.5.3' First, simply import matplotlib.pyplot as plt plt.arrow(2,2,4,1) doesn't show anything, while at least a figure with an arrow in is expected (or it's by design?) Secondly, with this simple script: import matplotlib.pyplot as plt plt.plot(range(10)) plt.arrow(2,2,4,1, linewidth=5) plt.arrow(3,3,1,4) the result is quite ugly :) Where is the arrow pointer (for example)? I hope I'm missing something, but even in examples like "usetex_demo" the arrows are drawn "by hand" :) Thanks, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi <>-- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
> The event.x and event.y is the position of the mouse, and often this > would not be the position of the legend (lower left corner) you want. > I guess a common practice is to calculate how much your mouse moved > since you started dragging and adjust the position of the legend from > its original position by the same amount. What I would do is, in the > on_pick call, save the current location of the mouse and the current > location of the legend. And, when on_motion is called, calculate the > dx, dy of your current mouse position from the saved (original) mouse > position, and set the location of the legend by adding the same amount > to the original legend position. Of course, the coordinate need to be > converted in a proper system. This is what I have attempted to do below. Here is the relevant part: #pick the legend def on_pick(self, event): legend = self.legend if event.artist == legend: bbox = self.legend.get_window_extent() #gets the box of the legend. self.mouse_x = event.mouseevent.x #get mouse coordinates at time of pick. self.mouse_y = event.mouseevent.y self.legend_x = bbox.xmin #get legend coordinates at time of pick. self.legend_y = bbox.ymin self.gotLegend = 1 #indicates we picked up the legend. #drag the legend def on_motion(self, event): if self.gotLegend == 1: mouse_diff_x = self.mouse_x - event.x #how much the mouse moved. mouse_diff_y = self.mouse_y - event.y #move the legend from its previous location by that same amount self.legend._loc=(self.legend_x + mouse_diff_x, self.legend_y + mouse_diff_y) self.canvas.draw() self.parent.Refresh() Now when I run this, the legend just disappears (well, is moved to somewhere off the screen). For those with wx installed, runnable sample follows... Thanks, Che #Boa:Frame:Frame1 import wx import matplotlib matplotlib.interactive(True) matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.figure import Figure def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, ] = [wx.NewId() for _init_ctrls in range(3)] class PlotPanel(wx.Panel): def __init__(self, parent,id = -1, color = None,\ dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): self.parent = parent self.line_collections_list = [] wx.Panel.__init__(self, parent, **kwargs) self.figure = Figure(None, dpi) self.canvas = FigureCanvasWxAgg( self, -1, self.figure ) #Connect all the mpl events self.canvas.mpl_connect('motion_notify_event', self.on_motion) self.canvas.mpl_connect('pick_event', self.on_pick) self.canvas.mpl_connect('button_release_event', self.on_release) self.gotLegend = 0 #to begin, legend is not picked. self._SetInitialSize() self.Bind(wx.EVT_SIZE, self._onSize) self.state = 'Initial' self.draw() def _onSize(self, event): self._SetSize() event.Skip() def _SetSize( self ): pixels = tuple( self.GetClientSize() ) self.SetSize( pixels ) self.canvas.SetSize( pixels ) self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(), float( pixels[1] )/self.figure.get_dpi() ) def _SetInitialSize(self,): pixels = self.parent.GetClientSize() self.canvas.SetSize(pixels) self.figure.set_size_inches( (pixels[0])/self.figure.get_dpi(), (pixels[1])/self.figure.get_dpi(), forward=True ) def draw(self): self.subplot = self.figure.add_subplot(111) line, = self.subplot.plot([1,2,3],[4,5,6],'o',picker=5) self.line_collections_list.append(line) #Legend self.legend = self.subplot.legend(self.line_collections_list, ['1'], numpoints=1) self.legend.set_picker(self.my_legend_picker) #pick up the legend patch def my_legend_picker(self, legend, event): return self.legend.legendPatch.contains(event) #pick the legend def on_pick(self, event): legend = self.legend if event.artist == legend: bbox = self.legend.get_window_extent() #gets the box of the legend. self.mouse_x = event.mouseevent.x #get mouse coordinates at time of pick. self.mouse_y = event.mouseevent.y self.legend_x = bbox.xmin #get legend coordinates at time of pick. self.legend_y = bbox.ymin self.gotLegend = 1 #indicates we picked up the legend. #drag the legend def on_motion(self, event): if self.gotLegend == 1: mouse_diff_x = self.mouse_x - event.x #how much the mouse moved. mouse_diff_y = self.mouse_y - event.y #move the legend from its pr
Re: [Matplotlib-users] Trying to plot -- problem with date2num?
Hi JDH, Thanks for looking into this -- it has been driving me crazy! I tried running your much better code but ended up with the same result: http://screencast.com/t/UMl6l0Y4 I checked and matplotlib is version 0.98.5.2, and your code doesn't using dateutil so I guess that's not it. Any other ideas? I can't think of what else to try... Thanks again, Tyler On Wed, Mar 25, 2009 at 5:38 PM, John Hunter wrote: > > > On Wed, Mar 25, 2009 at 3:25 PM, Tyler B wrote: >> >> And yet here is the result: http://screencast.com/t/gLPDFtwnJM4 >> >> I can't figure out why the values are 'grouping' around particular values >> on the x-axis... I would expect it to look more like a function, with only >> one y-value for each x. > > I am not seeing the problem when I run your script with your datafile (there > is no grouping in columns like you have; instead I get a distinct x for each > date). I wonder if you have an old dateutil or an old matplotlib. > > With recent matplotlib, you can do with less code:: > > import matplotlib.cbook as cbook > import matplotlib.mlab as mlab > import matplotlib.pyplot as plt > r = mlab.csv2rec('gmail-count.txt', names='date,val1,val2', > converterd={'date' : cbook.todatetime('%Y-%m-%d > %H:%M:%S')}) > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot(r.date, r.val1, 'g^') > fig.autofmt_xdate () > plt.show() > > > JDH > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Trying to plot -- problem with date2num?
On Wed, Mar 25, 2009 at 3:25 PM, Tyler B wrote: > > And yet here is the result: http://screencast.com/t/gLPDFtwnJM4 > > I can't figure out why the values are 'grouping' around particular values > on the x-axis... I would expect it to look more like a function, with only > one y-value for each x. > I am not seeing the problem when I run your script with your datafile (there is no grouping in columns like you have; instead I get a distinct x for each date). I wonder if you have an old dateutil or an old matplotlib. With recent matplotlib, you can do with less code:: import matplotlib.cbook as cbook import matplotlib.mlab as mlab import matplotlib.pyplot as plt r = mlab.csv2rec('gmail-count.txt', names='date,val1,val2', converterd={'date' : cbook.todatetime('%Y-%m-%d %H:%M:%S')}) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(r.date, r.val1, 'g^') fig.autofmt_xdate () plt.show() JDH -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Hi Che, I think you got bit by the "reply to list" non-feature of this list... >> In ours, we catch the mpl button down event and after establishing a >> hit on the legend do: > > I was using the pick event, not the button down event. How do you > "establish a hit on the legend" in the button down event handler? So, keep in mind that we're using 0.90.1. This was before the nice hit-test routines. We wrote our own hit-test routines loosely based around the "object_picker.py" demo that was current at the time. >> bbox = self._legend.get_window_extent() >> self._dragOffset = (bbox.xmin() - mplEvent.x, bbox.ymin() >> - mplEvent.y) >> >> Then in the mousemove event handler we do: >> >> self._moveLegend(mplEvent.x + self._dragOffset[0], >> mplEvent.y + self._dragOffset[1]) >> >> where self._moveLegend is: >> >> def _moveLegend(self, x, y, autoDraw=True): > > What is the purpose of autoDraw = True? This is something we carry around in our application to limit the number of redraws to reduce flicker. >> height = float(self.figure.bbox.height()) >> width = float(self.figure.bbox.width()) > > Can someone confirm that in the most recent version of mpl, > one can no longer do bbox.height(), but must just do bbox.height ? > (when I do it the first way it says float is not callable). I'm pretty sure this is true. >> dx = x/width >> dy = y/height >> >> # The following two lines are specific to our implementation >> and our internal data classes >> self._legendLocation = (dx, dy) >> self.plot.getLegend().setLocation(self._legendLocation) > > So can I exclude them and still get the legend to move? Yes. >> # This is the line that "moves" the legend >> self._legend._loc=(dx,dy) >> >> if autoDraw: >> self.draw() >> >> Now we're using an ancient version of MPL (0.90.1) and many things >> have changed in the meantime. YMMV. > > Thanks very much, > Che No worries. A> -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Fwd: Trying to plot -- problem with date2num?
Sorry to spam.. I was advised to re-send this as plain text. Thanks for any help! Hi there, I'm trying to plot a file which keeps track of my inbox count over time. Every minute it creates an observation, recording a timestamp, and the inbox count, like this: 2009-03-25 08:33:48, 5 2009-03-25 08:34:48, 5 2009-03-25 08:35:48, 5 ... and so on. I have about a day's worth of data so far. Here is code I'm trying to use to plot this: > import dateutil, pylab, csv, matplotlib > import numpy as np > import matplotlib.pyplot as plt > import matplotlib.dates as mdates > > # Used for axis formatting > days = mdates.DayLocator() # every day > hours = mdates.HourLocator() # every month > daysFmt = mdates.DateFormatter('%D') > > # Open data file > data = csv.reader(open('gmail-count.txt'), delimiter=',') > > # Convert to vectors > time = [] > inbox = [] > for c_time, c_inbox in data: > time.append(c_time) > inbox.append(int(c_inbox)) > > # Plot the data > x_dates = pylab.date2num([dateutil.parser.parse(s) for s in time]) > print x_dates > > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot(x_dates, inbox, 'g^') > > # format the ticks > ax.xaxis.set_major_locator(days) > ax.xaxis.set_major_formatter(daysFmt) > ax.xaxis.set_minor_locator(hours) > fig.autofmt_xdate() > > # Save the file > plt.savefig('testA') And yet here is the result: http://screencast.com/t/gLPDFtwnJM4 I can't figure out why the values are 'grouping' around particular values on the x-axis... I would expect it to look more like a function, with only one y-value for each x. Am I using date2num wrongly, or can anyone please suggest where I might be going wrong? (In case anyone wants to see the data, I've attached it as well.. just ignore the 3rd column) Thanks! Tyler 2009-03-24 18:57:48,8,17 2009-03-24 18:58:48,8,17 2009-03-24 18:59:48,8,17 2009-03-24 19:00:48,8,17 2009-03-24 19:01:48,8,17 2009-03-24 19:03:10,8,17 2009-03-24 19:03:48,8,17 2009-03-24 19:04:48,8,17 2009-03-24 19:05:48,8,17 2009-03-24 19:06:48,8,17 2009-03-24 19:07:48,8,17 2009-03-24 19:08:48,8,17 2009-03-24 19:09:48,8,17 2009-03-24 19:10:48,8,17 2009-03-24 19:11:48,8,17 2009-03-24 19:12:48,8,17 2009-03-24 19:13:48,8,17 2009-03-24 19:14:48,8,17 2009-03-24 19:15:48,8,17 2009-03-24 19:16:48,8,17 2009-03-24 19:17:48,8,17 2009-03-24 19:18:48,8,17 2009-03-24 19:19:48,8,17 2009-03-24 19:20:48,8,17 2009-03-24 19:21:51,9,17 2009-03-24 19:22:48,9,17 2009-03-24 19:23:50,9,17 2009-03-24 19:24:48,9,17 2009-03-24 19:25:48,9,17 2009-03-24 19:26:48,9,17 2009-03-24 19:27:48,9,17 2009-03-24 19:28:48,9,17 2009-03-24 19:29:48,9,17 2009-03-24 19:30:48,9,17 2009-03-24 19:31:48,9,17 2009-03-24 19:32:48,9,17 2009-03-24 19:33:48,9,17 2009-03-24 19:34:48,9,17 2009-03-24 19:35:48,9,17 2009-03-24 19:36:48,9,17 2009-03-24 19:37:48,9,17 2009-03-24 19:38:48,9,17 2009-03-24 19:39:48,9,17 2009-03-24 19:40:48,9,17 2009-03-24 19:41:48,9,17 2009-03-24 19:42:48,9,17 2009-03-24 19:43:48,9,17 2009-03-24 19:44:48,9,17 2009-03-24 19:45:48,9,17 2009-03-24 19:46:48,9,17 2009-03-24 19:47:49,9,17 2009-03-24 19:48:48,9,17 2009-03-24 19:49:49,9,17 2009-03-24 19:50:48,9,17 2009-03-24 19:51:49,9,17 2009-03-24 19:52:48,9,17 2009-03-24 19:53:50,9,17 2009-03-24 19:54:49,9,17 2009-03-24 19:55:48,9,17 2009-03-24 19:56:48,9,17 2009-03-24 19:57:48,9,17 2009-03-24 19:58:49,9,17 2009-03-24 19:59:53,9,17 2009-03-24 20:00:49,9,17 2009-03-24 20:01:49,9,17 2009-03-24 20:02:48,9,17 2009-03-24 20:03:48,9,17 2009-03-24 20:04:48,9,17 2009-03-24 20:05:49,9,17 2009-03-24 20:06:49,9,17 2009-03-24 20:07:48,9,17 2009-03-24 20:08:48,9,17 2009-03-24 20:09:49,9,17 2009-03-24 20:10:48,9,17 2009-03-24 20:11:52,9,17 2009-03-24 20:12:52,9,17 2009-03-24 20:13:52,9,17 2009-03-24 20:14:52,9,17 2009-03-24 20:15:51,9,17 2009-03-24 20:16:50,9,17 2009-03-24 20:17:52,9,17 2009-03-24 20:18:52,9,17 2009-03-24 20:19:52,9,17 2009-03-24 20:20:51,9,17 2009-03-24 20:21:51,9,17 2009-03-24 20:22:51,9,17 2009-03-24 20:23:52,9,17 2009-03-24 20:24:50,9,17 2009-03-24 20:25:50,9,17 2009-03-24 20:26:51,9,17 2009-03-24 20:27:52,9,17 2009-03-24 20:28:51,9,17 2009-03-24 20:29:52,9,17 2009-03-24 20:30:52,9,17 2009-03-24 20:31:52,9,17 2009-03-24 20:32:53,9,17 2009-03-24 20:33:52,9,17 2009-03-24 20:34:51,9,17 2009-03-24 20:35:52,9,17 2009-03-24 20:36:53,9,17 2009-03-24 20:37:50,9,17 2009-03-24 20:38:52,9,17 2009-03-24 20:39:50,9,17 2009-03-24 20:40:51,9,17 2009-03-24 20:41:51,9,17 2009-03-24 20:42:51,9,17 2009-03-24 20:43:50,9,17 2009-03-24 20:44:52,9,17 2009-03-24 20:45:51,9,17 2009-03-24 20:46:51,9,17 2009-03-24 20:47:50,9,17 2009-03-24 20:48:52,9,17 2009-03-24 20:49:51,9,17 2009-03-24 20:50:51,9,17 2009-03-24 20:51:51,9,17 2009-03-24 20:52:58,9,17 2009-03-24 20:53:51,9,17 2009-03-24 20:54:55,9,17 2009-03-24 20:55:51,9,17 2009-03-24 20:56:51,9,17 2009-03-24 20:57:51,9,17 2009-03-24 20:58:51,9,17 2009-03-24 20:59:51,9,17 2009-03-24 21:00:51,9,17 2009-03-24 21:01:51,9,17 2009-03-24 21:02:51,9,17 2009-03-24 21:03:51,9,17 2009-03-24 21:04:48,9,17 2009-03-24 21:05:
[Matplotlib-users] Trying to plot -- problem with date2num?
Hi there, I'm trying to plot a file which keeps track of my inbox count over time. Every minute it creates an observation, recording a timestamp, and the inbox count, like this: 2009-03-25 08:33:48, 5 2009-03-25 08:34:48, 5 2009-03-25 08:35:48, 5 ... and so on. I have about a day's worth of data so far. Here is code I'm trying to use to plot this: import dateutil, pylab, csv, matplotlib > import numpy as np > import matplotlib.pyplot as plt > import matplotlib.dates as mdates > > # Used for axis formatting > days= mdates.DayLocator() # every day > hours = mdates.HourLocator() # every month > daysFmt = mdates.DateFormatter('%D') > > # Open data file > data = csv.reader(open('gmail-count.txt'), delimiter=',') > > # Convert to vectors > time = [] > inbox = [] > for c_time, c_inbox in data: > time.append(c_time) > inbox.append(int(c_inbox)) > > # Plot the data > x_dates = pylab.date2num([dateutil.parser.parse(s) for s in time]) > print x_dates > > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot(x_dates, inbox, 'g^') > > # format the ticks > ax.xaxis.set_major_locator(days) > ax.xaxis.set_major_formatter(daysFmt) > ax.xaxis.set_minor_locator(hours) > fig.autofmt_xdate() > > # Save the file > plt.savefig('testA') And yet here is the result: http://screencast.com/t/gLPDFtwnJM4 I can't figure out why the values are 'grouping' around particular values on the x-axis... I would expect it to look more like a function, with only one y-value for each x. Am I using date2num wrongly, or can anyone please suggest where I might be going wrong? (In case anyone wants to see the data, I've attached it as well.. just ignore the 3rd column) Thanks! Tyler 2009-03-24 18:57:48,8,17 2009-03-24 18:58:48,8,17 2009-03-24 18:59:48,8,17 2009-03-24 19:00:48,8,17 2009-03-24 19:01:48,8,17 2009-03-24 19:03:10,8,17 2009-03-24 19:03:48,8,17 2009-03-24 19:04:48,8,17 2009-03-24 19:05:48,8,17 2009-03-24 19:06:48,8,17 2009-03-24 19:07:48,8,17 2009-03-24 19:08:48,8,17 2009-03-24 19:09:48,8,17 2009-03-24 19:10:48,8,17 2009-03-24 19:11:48,8,17 2009-03-24 19:12:48,8,17 2009-03-24 19:13:48,8,17 2009-03-24 19:14:48,8,17 2009-03-24 19:15:48,8,17 2009-03-24 19:16:48,8,17 2009-03-24 19:17:48,8,17 2009-03-24 19:18:48,8,17 2009-03-24 19:19:48,8,17 2009-03-24 19:20:48,8,17 2009-03-24 19:21:51,9,17 2009-03-24 19:22:48,9,17 2009-03-24 19:23:50,9,17 2009-03-24 19:24:48,9,17 2009-03-24 19:25:48,9,17 2009-03-24 19:26:48,9,17 2009-03-24 19:27:48,9,17 2009-03-24 19:28:48,9,17 2009-03-24 19:29:48,9,17 2009-03-24 19:30:48,9,17 2009-03-24 19:31:48,9,17 2009-03-24 19:32:48,9,17 2009-03-24 19:33:48,9,17 2009-03-24 19:34:48,9,17 2009-03-24 19:35:48,9,17 2009-03-24 19:36:48,9,17 2009-03-24 19:37:48,9,17 2009-03-24 19:38:48,9,17 2009-03-24 19:39:48,9,17 2009-03-24 19:40:48,9,17 2009-03-24 19:41:48,9,17 2009-03-24 19:42:48,9,17 2009-03-24 19:43:48,9,17 2009-03-24 19:44:48,9,17 2009-03-24 19:45:48,9,17 2009-03-24 19:46:48,9,17 2009-03-24 19:47:49,9,17 2009-03-24 19:48:48,9,17 2009-03-24 19:49:49,9,17 2009-03-24 19:50:48,9,17 2009-03-24 19:51:49,9,17 2009-03-24 19:52:48,9,17 2009-03-24 19:53:50,9,17 2009-03-24 19:54:49,9,17 2009-03-24 19:55:48,9,17 2009-03-24 19:56:48,9,17 2009-03-24 19:57:48,9,17 2009-03-24 19:58:49,9,17 2009-03-24 19:59:53,9,17 2009-03-24 20:00:49,9,17 2009-03-24 20:01:49,9,17 2009-03-24 20:02:48,9,17 2009-03-24 20:03:48,9,17 2009-03-24 20:04:48,9,17 2009-03-24 20:05:49,9,17 2009-03-24 20:06:49,9,17 2009-03-24 20:07:48,9,17 2009-03-24 20:08:48,9,17 2009-03-24 20:09:49,9,17 2009-03-24 20:10:48,9,17 2009-03-24 20:11:52,9,17 2009-03-24 20:12:52,9,17 2009-03-24 20:13:52,9,17 2009-03-24 20:14:52,9,17 2009-03-24 20:15:51,9,17 2009-03-24 20:16:50,9,17 2009-03-24 20:17:52,9,17 2009-03-24 20:18:52,9,17 2009-03-24 20:19:52,9,17 2009-03-24 20:20:51,9,17 2009-03-24 20:21:51,9,17 2009-03-24 20:22:51,9,17 2009-03-24 20:23:52,9,17 2009-03-24 20:24:50,9,17 2009-03-24 20:25:50,9,17 2009-03-24 20:26:51,9,17 2009-03-24 20:27:52,9,17 2009-03-24 20:28:51,9,17 2009-03-24 20:29:52,9,17 2009-03-24 20:30:52,9,17 2009-03-24 20:31:52,9,17 2009-03-24 20:32:53,9,17 2009-03-24 20:33:52,9,17 2009-03-24 20:34:51,9,17 2009-03-24 20:35:52,9,17 2009-03-24 20:36:53,9,17 2009-03-24 20:37:50,9,17 2009-03-24 20:38:52,9,17 2009-03-24 20:39:50,9,17 2009-03-24 20:40:51,9,17 2009-03-24 20:41:51,9,17 2009-03-24 20:42:51,9,17 2009-03-24 20:43:50,9,17 2009-03-24 20:44:52,9,17 2009-03-24 20:45:51,9,17 2009-03-24 20:46:51,9,17 2009-03-24 20:47:50,9,17 2009-03-24 20:48:52,9,17 2009-03-24 20:49:51,9,17 2009-03-24 20:50:51,9,17 2009-03-24 20:51:51,9,17 2009-03-24 20:52:58,9,17 2009-03-24 20:53:51,9,17 2009-03-24 20:54:55,9,17 2009-03-24 20:55:51,9,17 2009-03-24 20:56:51,9,17 2009-03-24 20:57:51,9,17 2009-03-24 20:58:51,9,17 2009-03-24 20:59:51,9,17 2009-03-24 21:00:51,9,17 2009-03-24 21:01:51,9,17 2009-03-24 21:02:51,9,17 2009-03-24 21:03:51,9,17 2009-03-24 21:04:48,9,17 2009-03-24 21:05:51,9,17 2009-03-24 21:06:51,9,17 2009-03-24 21:07:52,9,17 2009-03-24 21:08:52,9,17 2
Re: [Matplotlib-users] axhline in OO interface?
1st: Sorry about the stupid questions -- I was under a lot of time pressure yesterday. John Hunter wrote: > The search tool on the website is actually pretty decent > > http://matplotlib.sourceforge.net/search.html?q=axhline Yes that is very nice -- I'll make sure to try that in the future. However, that only works if you can make a good stab at the name of a method. > mailto:chris.bar...@noaa.gov>> wrote: > I am finding it harder to navigate the API docs than I'd like -- I > m not sure what could be done, however. One thing that might help would > be an index of all methods at the top of the class docs -- there is a > lot of good stuff in each of the methods docs, so it gets hard to > quickly look for a method. So it would still be nice to have a better way to browse the docs. But the new docs really are looking great! The truth is, I haven't used MPL for anything of significance for a good while, and I was yesterday able to whip out a bunch of custom plots in short order for an emergency response -- a testament to the wonders of Matplotlib! by the way, I'm off to PyCon tomorrow -- are you going to be there John? It's in your neighborhood, yes? -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 chris.bar...@noaa.gov -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] problems installing matplotlib
Doh! I was misinterpreting what the message meant. So, what it is saying is that it found those things, even libpng, but was then attempting for some reason to make a connection to my X server, and failing because of my convoluted connections. Sigh. I had interpreted that part of the message as the script attempting to connect to some site to get the dependencies! haha. Well, unsetting DISPLAY did the trick! Thanks for the enlightenment. George Jouni K. Seppänen wrote: George Myers writes: However, when I try 2.5.3 for example I am getting the following: The following looks like the script found numpy and freetype just fine: REQUIRED DEPENDENCIES numpy: 1.2.1 freetype2: 9.8.3 But then there was some other problem: OPTIONAL BACKEND DEPENDENCIES libpng: 1.2.8 X11 connection rejected because of wrong authentication. X connection to cfe3:42.0 broken (explicit kill or server shutdown). I don't know why it's trying to open an X11 connection, but it could be caused by some of the toolkit checks related to the interactive backends. Does it help to unset DISPLAY when running setup.py, as follows? env DISPLAY= /path/to/python25 setup.py Perhaps there is a step that I need to do before running python setup.py build that I am unaware of. I am not all that familiar with python in general. One slightly subtle thing is that if PKG_CONFIG_PATH is used to determine which version of freetype gets used - setupext.py calls pkg-config to find the compilation flags. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
Hi Che, There is still a problem with offset, but the legend seems to move the same distance as the mouse if you get height and width from the axes instead of the figure: def on_motion(self, event): height = float(self.figure.axes[0].bbox.height) width = float(self.figure.axes[0].bbox.width) -- Christopher Brown, Ph.D. Department of Speech and Hearing Science Arizona State University -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
On Tue, Mar 24, 2009 at 11:37 PM, C M wrote: > Using mpl 0.98.5.2 in OO mode with wxAgg backend. > > I'm trying to make my legends draggable. It works, but > there is a some inaccuracy with positioning. As I drag it, > the cursor "outruns" the position of the legend, and that > error grows the further away from the initial starting point > the cursor has been moved. It makes the feel of dragging > completely wrong. > > The work of repositioning the legend is done in an > on_motion event. self.figure here is a mpl Figure. > The motion event handler is: > > #drag the legend > def on_motion(self, event): > height = float(self.figure.bbox.height) > width = float(self.figure.bbox.width) > > dx = event.x/width > dy = event.y/height > > if self.gotLegend == 1: #it's picked up > self.legend._loc=(dx,dy) #reposition it > self.canvas.draw() > self.parent.Refresh() > Weird. This is essentially what we do, but in our case there's no problem. I ran your example and experienced the same "outrun" behavior so I checked to see what was different between yours and ours. In ours, we catch the mpl button down event and after establishing a hit on the legend do: bbox = self._legend.get_window_extent() self._dragOffset = (bbox.xmin() - mplEvent.x, bbox.ymin() - mplEvent.y) Then in the mousemove event handler we do: self._moveLegend(mplEvent.x + self._dragOffset[0], mplEvent.y + self._dragOffset[1]) where self._moveLegend is: def _moveLegend(self, x, y, autoDraw=True): height = float(self.figure.bbox.height()) width = float(self.figure.bbox.width()) dx = x/width dy = y/height # The following two lines are specific to our implementation and our internal data classes self._legendLocation = (dx, dy) self.plot.getLegend().setLocation(self._legendLocation) # This is the line that "moves" the legend self._legend._loc=(dx,dy) if autoDraw: self.draw() Now we're using an ancient version of MPL (0.90.1) and many things have changed in the meantime. YMMV. A> -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Leftmost column of PNG output is transparent
Maybe I'll try the latest SVN version. I'm running the version in the ubuntu 8.10 repositories, which appears to be 0.98.3 As for both contourf and pcolor, I was just testing to see that it was messed up either way, leaving one commented and one uncommented. Having them both uncommented was just a typo, but the problem persists either way. Thanks, Kevin Jae-Joon Lee wrote: > I couldn't reproduce it (my output has no transparent column). I'm > running the current svn. I wonder if others can reproduce it. > > Kevin, > what happen if you only do one of the pcolor or the contourf (it is > not clear why you're calling pcolor as it will be overridden by > contourf)? > > -JJ > > > On Mon, Mar 23, 2009 at 5:10 PM, kmilner wrote: > >> Hi All, >> >> I'm trying to plot evenly grided data to tiles for google maps overlays. >> Each tile needs to be a 256x256 pixel PNG image, without any borders. >> >> The problem that I'm having is that the leftmost column of the resultant PNG >> image (saved using FigureCanvasAgg.print_figure) is transparent. >> >> My real code uses basemap because the output has to be in the mercator >> projection, but the sample code below is simplified to exclude it. You can >> view the sample image that is produced at this address: >> http://earth.usc.edu/ftp/kmilner/trans_test.png >> >> Any ideas? >> >> Thanks! >> Kevin >> >> #!/usr/bin/env python >> >> from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas >> from matplotlib.figure import Figure >> import numpy >> >> dpi = 64 >> pixels = 256 >> fig = Figure(linewidth=0, frameon=False) >> canvas = FigureCanvas(fig) >> >> fig.figurePatch.set_alpha(0.0) >> >> ax_bounds = [0, 0, 1, 1] >> >> ax = fig.add_axes(ax_bounds, axisbg=(1.0,1.0,0.0,0.0), >>frameon=False ) >> >> inches = pixels / dpi >> fig.set_size_inches(256 / dpi, 256 / dpi) >> >> num = 31 >> >> z = numpy.empty( (num, num) ) >> >> for x in xrange(num): >>for y in xrange(num): >>z[x, y] = x * y >> >> x, y = numpy.meshgrid( range(num), range(num) ) >> >> image = ax.pcolor(x, y, z) >> image = ax.contourf(x, y, z) >> >> canvas.print_figure("/tmp/trans_test.png", dpi=dpi) >> -- >> View this message in context: >> http://www.nabble.com/Leftmost-column-of-PNG-output-is-transparent-tp22669232p22669232.html >> Sent from the matplotlib - users mailing list archive at Nabble.com. >> >> >> -- >> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are >> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and >> easily build your RIAs with Flex Builder, the Eclipse(TM)based development >> software that enables intelligent coding and step-through debugging. >> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Leftmost column of PNG output is transparent
I couldn't reproduce it (my output has no transparent column). I'm running the current svn. I wonder if others can reproduce it. Kevin, what happen if you only do one of the pcolor or the contourf (it is not clear why you're calling pcolor as it will be overridden by contourf)? -JJ On Mon, Mar 23, 2009 at 5:10 PM, kmilner wrote: > > Hi All, > > I'm trying to plot evenly grided data to tiles for google maps overlays. > Each tile needs to be a 256x256 pixel PNG image, without any borders. > > The problem that I'm having is that the leftmost column of the resultant PNG > image (saved using FigureCanvasAgg.print_figure) is transparent. > > My real code uses basemap because the output has to be in the mercator > projection, but the sample code below is simplified to exclude it. You can > view the sample image that is produced at this address: > http://earth.usc.edu/ftp/kmilner/trans_test.png > > Any ideas? > > Thanks! > Kevin > > #!/usr/bin/env python > > from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas > from matplotlib.figure import Figure > import numpy > > dpi = 64 > pixels = 256 > fig = Figure(linewidth=0, frameon=False) > canvas = FigureCanvas(fig) > > fig.figurePatch.set_alpha(0.0) > > ax_bounds = [0, 0, 1, 1] > > ax = fig.add_axes(ax_bounds, axisbg=(1.0,1.0,0.0,0.0), > frameon=False ) > > inches = pixels / dpi > fig.set_size_inches(256 / dpi, 256 / dpi) > > num = 31 > > z = numpy.empty( (num, num) ) > > for x in xrange(num): > for y in xrange(num): > z[x, y] = x * y > > x, y = numpy.meshgrid( range(num), range(num) ) > > image = ax.pcolor(x, y, z) > image = ax.contourf(x, y, z) > > canvas.print_figure("/tmp/trans_test.png", dpi=dpi) > -- > View this message in context: > http://www.nabble.com/Leftmost-column-of-PNG-output-is-transparent-tp22669232p22669232.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > > > -- > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] offset in dragging a legend
I don't have wx installed, so i'm not able to test your code. However, here are some of my thoughts. The location of the legend is the location of the lower-left corner in the normalized coordinate of its parent. In your case, it would be normalized "axes" coordinates. However, it seems that you're setting the legend location in the normalized "figure" coordinate. http://matplotlib.sourceforge.net/api/artist_api.html#module-matplotlib.legend The event.x and event.y is the position of the mouse, and often this would not be the position of the legend (lower left corner) you want. I guess a common practice is to calculate how much your mouse moved since you started dragging and adjust the position of the legend from its original position by the same amount. What I would do is, in the on_pick call, save the current location of the mouse and the current location of the legend. And, when on_motion is called, calculate the dx, dy of your current mouse position from the saved (original) mouse position, and set the location of the legend by adding the same amount to the original legend position. Of course, the coordinate need to be converted in a proper system. IHTH, -JJ On Wed, Mar 25, 2009 at 2:37 AM, C M wrote: > Using mpl 0.98.5.2 in OO mode with wxAgg backend. > > I'm trying to make my legends draggable. It works, but > there is a some inaccuracy with positioning. As I drag it, > the cursor "outruns" the position of the legend, and that > error grows the further away from the initial starting point > the cursor has been moved. It makes the feel of dragging > completely wrong. > > The work of repositioning the legend is done in an > on_motion event. self.figure here is a mpl Figure. > The motion event handler is: > > #drag the legend > def on_motion(self, event): > height = float(self.figure.bbox.height) > width = float(self.figure.bbox.width) > > dx = event.x/width > dy = event.y/height > > if self.gotLegend == 1: #it's picked up > self.legend._loc=(dx,dy) #reposition it > self.canvas.draw() > self.parent.Refresh() > > Any idea why this is wrong? I cobbled this from > a few sources online and boiled it down to this. > I am confused as to why it should use dx and dy > instead of just the exact position of the mouse. > > Any ideas are appreciated, and full runnable > sample is below. > > Thanks, > Che > > > #Boa:Frame:Frame1 > > import wx > > import matplotlib > matplotlib.interactive(True) > matplotlib.use('WXAgg') > from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg > from matplotlib.figure import Figure > > def create(parent): > return Frame1(parent) > > [wxID_FRAME1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, > ] = [wx.NewId() for _init_ctrls in range(3)] > > class PlotPanel(wx.Panel): > def __init__(self, parent,id = -1, color = None,\ > dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): > > self.parent = parent > self.line_collections_list = [] > > wx.Panel.__init__(self, parent, **kwargs) > > self.figure = Figure(None, dpi) > self.canvas = FigureCanvasWxAgg( self, -1, self.figure ) > > #Connect all the mpl events > self.canvas.mpl_connect('motion_notify_event', self.on_motion) > self.canvas.mpl_connect('pick_event', self.on_pick) > self.canvas.mpl_connect('button_release_event', self.on_release) > > self.gotLegend = 0 #to begin, legend is not picked. > > self._SetInitialSize() > > self.Bind(wx.EVT_SIZE, self._onSize) > self.state = 'Initial' > self.draw() > > def _onSize(self, event): > self._SetSize() > event.Skip() > > def _SetSize( self ): > pixels = tuple( self.GetClientSize() ) > self.SetSize( pixels ) > self.canvas.SetSize( pixels ) > self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(), > float( pixels[1] )/self.figure.get_dpi() ) > > def _SetInitialSize(self,): > pixels = self.parent.GetClientSize() > self.canvas.SetSize(pixels) > self.figure.set_size_inches( (pixels[0])/self.figure.get_dpi(), > (pixels[1])/self.figure.get_dpi(), forward=True ) > > > def draw(self): > self.subplot = self.figure.add_subplot(111) > line, = self.subplot.plot([1,2,3],[4,5,6],'o',picker=5) > self.line_collections_list.append(line) > > #Legend > self.legend = self.subplot.legend(self.line_collections_list, > ['datum'], 'right', > numpoints=1) > self.legend.set_picker(self.my_legend_picker) > > #pick up the legend patch > def my_legend_picker(self, legend, event): > return self.legend.legendPatch.contains(event) > > #pick the legend > def on_pick(self, event): > legend = self.legend > if event.artist == legend: > self.gotLegend = 1 > > #drag the legend > #(This doesn'
Re: [Matplotlib-users] problems installing matplotlib
George Myers writes: > However, when I try 2.5.3 for example I am getting the following: The following looks like the script found numpy and freetype just fine: > REQUIRED DEPENDENCIES > numpy: 1.2.1 > freetype2: 9.8.3 But then there was some other problem: > OPTIONAL BACKEND DEPENDENCIES > libpng: 1.2.8 > X11 connection rejected because of wrong authentication. > X connection to cfe3:42.0 broken (explicit kill or server shutdown). I don't know why it's trying to open an X11 connection, but it could be caused by some of the toolkit checks related to the interactive backends. Does it help to unset DISPLAY when running setup.py, as follows? env DISPLAY= /path/to/python25 setup.py > Perhaps there is a step that I need to do before running python > setup.py build that I am unaware of. I am not all that familiar with > python in general. One slightly subtle thing is that if PKG_CONFIG_PATH is used to determine which version of freetype gets used - setupext.py calls pkg-config to find the compilation flags. -- Jouni K. Seppänen http://www.iki.fi/jks -- Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users