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
matplotlib-users List Signup and Options

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
matplotlib-users List Signup and Options

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
matplotlib-users List Signup and Options

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
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
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
matplotlib-users List Signup and Options

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
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
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
matplotlib-users List Signup and Options

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
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
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
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
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
matplotlib-users List Signup and Options