[Matplotlib-users] Annotate with icon
Hi all, Is there any way to annotate a plot with icons? The only way to include an image that I've found is using imshow, but imshow does not accept (x,y) coordinates. There probably is an easy solution, but I have not been able to find any. Please be patient :-) Thank you in advance for your reply, Bas van Leeuwen -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Fwd: Annotate with icon
Hi all, Is there any way to annotate a plot with icons? The only way to include an image that I've found is using imshow, but imshow does not accept (x,y) coordinates. There probably is an easy solution, but I have not been able to find any. Please be patient :-) Thank you in advance for your reply, Bas van Leeuwen -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Include icon in plot
Hi all, Is there any way to annotate a plot with icons? The only way to include an image that I've found is using imshow, but imshow does not accept (x,y) coordinates. There probably is an easy solution, but I have not been able to find any. Please be patient :-) Thank you in advance for your reply, Bas van Leeuwen PS, I'm sorry if this mail arrives multiple times, I didn't see the previous one in the archive. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Include icon in plot
Hi JJ, Thank you for your kind and speedy reply, I completely glanced over the extent parameter. Datacoords are actually what I need so this is perfect for me. To clarify what I want, I want to mark certain parts of a graph with an icon representing the reason it's interesting. Icons are for peaks, trends, correlation, etc. Thank you very much! Bas 2009/7/30 Jae-Joon Lee : > The location of the image can be set by specifying the "extent" > keyword, however, this is set in data coordinate. > figimage may be close to what you want. > > http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.figimage > > As far as I know, there is no direct support in matplotlib to place an > image with arbitrary transformation. But it may not be difficult to > implement. However, "annotate a plot with icons" is not enough to > figure out what you really want. > Maybe some screenshots from other plotting tool will be helpful. Or, > please elaborate how you want to position your image. > > -JJ > > > On Thu, Jul 30, 2009 at 12:11 PM, Bas van Leeuwen wrote: >> Hi all, >> >> Is there any way to annotate a plot with icons? >> The only way to include an image that I've found is using imshow, but >> imshow does not accept (x,y) coordinates. >> >> There probably is an easy solution, but I have not been able to find >> any. Please be patient :-) >> >> Thank you in advance for your reply, >> Bas van Leeuwen >> >> PS, I'm sorry if this mail arrives multiple times, I didn't see the >> previous one in the archive. >> >> -- >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day >> trial. Simplify your report design, integration and deployment - and focus on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Include icon in plot
Hello, I tried to implement a solution for this issue. Basically I want to give the x and y position in datacoords and the width + height in pixels. However, when using the following code: im = Image.open("../Icons/Program Icon.png") limx = self.mainAxes.get_xlim() limy = self.mainAxes.get_ylim() [x0, y0], [x1, y1] = self.mainAxes.bbox.get_points() datawidth = limx[1] - limx[0] dataheight = limy[1] - limy[0] pixelwidth = x1 - x0 pixelheight = y1 - y0 adaptedwidth = im.size[0] * (datawidth/pixelwidth) adaptedheight = im.size[1] * (dataheight/pixelheight) for peak in Blocks.peaks(self.quote.Close, self.peakSpanSlider.value()): self.mainAxes.imshow(im, origin = 'lower', extent = (date2num(peak.datetime), date2num(peak.datetime) + 100 , 400, 425)) # left right bottom top self.mainAxes.set_xlim(limx) self.mainAxes.set_ylim(limy) There is no visible result. When zooming in to a place where an image should be present I encounter the following error every time I move the mouse. Traceback (most recent call last): File "C:\Python25\lib\site-packages\matplotlib\backends\backend_qt4.py", line 135, in mouseReleaseEvent FigureCanvasBase.button_release_event( self, x, y, button ) File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", line 1198, in button_release_event self.callbacks.process(s, event) File "C:\Python25\lib\site-packages\matplotlib\cbook.py", line 155, in process func(*args, **kwargs) File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", line 2048, in release_zoom self.draw() File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", line 2070, in draw self.canvas.draw() File "C:\Python25\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 133, in draw FigureCanvasAgg.draw(self) File "C:\Python25\lib\site-packages\matplotlib\backends\backend_agg.py", line 279, in draw self.figure.draw(self.renderer) File "C:\Python25\lib\site-packages\matplotlib\figure.py", line 772, in draw for a in self.axes: a.draw(renderer) File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 1545, in draw im.draw(renderer) File "C:\Python25\lib\site-packages\matplotlib\image.py", line 233, in draw im = self.make_image(renderer.get_image_magnification()) File "C:\Python25\lib\site-packages\matplotlib\image.py", line 220, in make_image rx = widthDisplay / numcols ZeroDivisionError: float division Any idea what might cause this issue? Did I do something wrong? I know it's not pretty, but it should work right? Cheers! Bas 2009/7/30 Bas van Leeuwen : > Hi JJ, > > Thank you for your kind and speedy reply, I completely glanced over > the extent parameter. > Datacoords are actually what I need so this is perfect for me. > > To clarify what I want, I want to mark certain parts of a graph with > an icon representing the reason it's interesting. Icons are for peaks, > trends, correlation, etc. > > Thank you very much! > > Bas > > > 2009/7/30 Jae-Joon Lee : >> The location of the image can be set by specifying the "extent" >> keyword, however, this is set in data coordinate. >> figimage may be close to what you want. >> >> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.figimage >> >> As far as I know, there is no direct support in matplotlib to place an >> image with arbitrary transformation. But it may not be difficult to >> implement. However, "annotate a plot with icons" is not enough to >> figure out what you really want. >> Maybe some screenshots from other plotting tool will be helpful. Or, >> please elaborate how you want to position your image. >> >> -JJ >> >> >> On Thu, Jul 30, 2009 at 12:11 PM, Bas van Leeuwen wrote: >>> Hi all, >>> >>> Is there any way to annotate a plot with icons? >>> The only way to include an image that I've found is using imshow, but >>> imshow does not accept (x,y) coordinates. >>> >>> There probably is an easy solution, but I have not been able to find >>> any. Please be patient :-) >>> >>> Thank you in advance for your reply, >>> Bas van Leeuwen >>> >>> PS, I'm sorry if this mail arrives multiple times, I didn't see the >>> previous one in the archive. >>> >>> -- >>> Let Cry
Re: [Matplotlib-users] Include icon in plot
Hi, Sorry about the snippet, I will privide working code from now on. I found a reproduction path for the error, it occurs (seemingly random, but frequent) when there is more than one image in the plot and you try to zoom. Code: import Image from pylab import * im = Image.open("icon.png") ax = subplot(111) limx = ax.set_xlim((-5, 15)) limy = ax.set_ylim((-5, 15)) ax.set_autoscale_on(False) [x0, y0], [x1, y1] = ax.bbox.get_points() datawidth = limx[1] - limx[0] dataheight = limy[1] - limy[0] pixelwidth = x1 - x0 pixelheight = y1 - y0 adaptedwidth = im.size[0] * (datawidth / pixelwidth) adaptedheight = im.size[1] * (dataheight / pixelheight) for i in range(0,10,2): ax.imshow(im, origin="lower", extent=(i, i + adaptedwidth, i, i + adaptedheight)) plt.draw() show() Thank you very much for the support! Bas PS, @John, I'd like to try the imshow approach first because it is not in a figure but in a QT frame containing several subplots. But thank youfor the suggestion, I will try if the imshow approach appears fruitless. 2009/8/2 Jae-Joon Lee : > A snippet of code does not help in general. > Please take your time to create a simple, standalone code that > reproduces your problem and post that code in this mailing list so > that we can easily test. > > Here is the code, based on yours, that works for me. > > im = Image.open("icon.jpg") > > ax = gca() > limx = ax.get_xlim() > limy = ax.get_ylim() > ax.set_autoscale_on(False) > > [x0, y0], [x1, y1] = ax.bbox.get_points() > > datawidth = limx[1] - limx[0] > dataheight = limy[1] - limy[0] > pixelwidth = x1 - x0 > pixelheight = y1 - y0 > adaptedwidth = im.size[0] * (datawidth/pixelwidth) > adaptedheight = im.size[1] * (dataheight/pixelheight) > > ax.imshow(im, origin="lower", > extent=(0.5, 0.5+adaptedwidth, 0.5, 0.5+adaptedheight)) > > > plt.draw() > > -JJ > > > > On Fri, Jul 31, 2009 at 3:44 PM, Bas van Leeuwen wrote: >> Hello, >> >> I tried to implement a solution for this issue. Basically I want to >> give the x and y position in datacoords and the width + height in >> pixels. >> However, when using the following code: >> >> im = Image.open("../Icons/Program Icon.png") >> >> limx = self.mainAxes.get_xlim() >> limy = self.mainAxes.get_ylim() >> >> [x0, y0], [x1, y1] = self.mainAxes.bbox.get_points() >> >> datawidth = limx[1] - limx[0] >> dataheight = limy[1] - limy[0] >> pixelwidth = x1 - x0 >> pixelheight = y1 - y0 >> adaptedwidth = im.size[0] * (datawidth/pixelwidth) >> adaptedheight = im.size[1] * (dataheight/pixelheight) >> >> >> for peak in Blocks.peaks(self.quote.Close, >> self.peakSpanSlider.value()): >> self.mainAxes.imshow(im, origin = 'lower', extent = >> (date2num(peak.datetime), date2num(peak.datetime) + 100 , 400, 425)) # >> left right bottom top >> self.mainAxes.set_xlim(limx) >> self.mainAxes.set_ylim(limy) >> >> There is no visible result. When zooming in to a place where an image >> should be present I encounter the following error every time I move >> the mouse. >> >> Traceback (most recent call last): >> File "C:\Python25\lib\site-packages\matplotlib\backends\backend_qt4.py", >> line 135, in mouseReleaseEvent >> FigureCanvasBase.button_release_event( self, x, y, button ) >> File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", >> line 1198, in button_release_event >> self.callbacks.process(s, event) >> File "C:\Python25\lib\site-packages\matplotlib\cbook.py", line 155, in >> process >> func(*args, **kwargs) >> File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", >> line 2048, in release_zoom >> self.draw() >> File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", >> line 2070, in draw >> self.canvas.draw() >> File "C:\Python25\lib\site-packages\matplotlib\backends\backend_qt4agg.py", >> line 133, in draw >> FigureCanvasAgg.draw(self) >> File "C:\Python25\lib\site-packages\matplotlib\backends\backend_agg.py", >> line 279, in draw >> self.figure.draw(self.renderer) >> File "C:\Python25\lib\site-packages\matplotlib\figure.py", line 772, in draw >> for a in self.axes: a.draw(renderer) >> File "C:\Python25\lib\site-packages\matplotlib\axes.py",