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 :slight_smile:

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.

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 :slight_smile:

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

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 :slight_smile:

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

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 :slight_smile:

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

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<leeuwen@...287...> 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\(&quot;\.\./Icons/Program Icon\.png&quot;\)

       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 :slight_smile:

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

The other approach is to use a figimage and use the ax.transData
instance to convert data coords to fig coords for the offsets.

JDH

路路路

On Sun, Aug 2, 2009 at 1:28 PM, Jae-Joon Lee<lee.j.joon@...287...> wrote:

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.

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

路路路

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<leeuwen@...287...> 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\(&quot;\.\./Icons/Program Icon\.png&quot;\)

       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 :slight_smile:

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

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.

All matplotlib axes and subplots live in figures, you just may not
know it. The call to gca in your code below:

聽聽>> ax = gca()
聽聽>> limx = ax.get_xlim()

automatically creates a figure and adds the axes to is. So you can
still access the figure, eg

聽聽fig = ax.figure

You can then call figimage

聽聽# transform from axes coorrs (x,y) -> display coords (xo,yo)
聽聽xo, yo = ax.transData.transform_point((x,y))
聽聽fig.figimage(Z, xo, yo)

where Z is your image array

JDH

路路路

On Mon, Aug 3, 2009 at 6:55 AM, Bas van Leeuwen<leeuwen@...287...> wrote:

Hmm, your code runs just fine for me (of course with different icon,
but I don't think it matters).
Can you try to install the 0.99rc version of mpl and see if it solves
the problem?
Since the error is not reproduced in my side, I have little to help.

Also, try the figimage and see if you see a same error.

Regards,

-JJ

路路路

On Mon, Aug 3, 2009 at 7:55 AM, Bas van Leeuwen<leeuwen@...287...> wrote:

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

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<leeuwen@...287...> 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\(&quot;\.\./Icons/Program Icon\.png&quot;\)

       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 :slight_smile:

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

------------------------------------------------------------------------------
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