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 <leeuwen@...287...>:
路路路
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 <lee.j.joon@...287...>:
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<leeuwen@...287...> 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