How to draw an arrow using matplotlib

I tried with what you suggested to make an Arrow class. To

    > begin with, I only put an Line2D instance. I searched for
    > table stuff in axes.py, matlab.py to make the arrow
    > importable from matplotlib.matlab. Then I also try a very
    > very simple demo and I expect to see a simple
    > line. However, I can not see it. Could someone tell me what
    > is the problem. Here is my very very rudimental codes.

Nowhere in your code do you actually draw the arrows in self.arrows.
In Axes.draw you would need to do

    for arrow in self.arrows:
        arrow.draw(renderer)

And this should work.

However, you can avoid all the overhead of add_arrow, and keeping a
list of arrows in self.arrows simply by doing

     def arrow(self, x, y, *args, **kwargs):
         a = Arrow(x,y, *args, **kwargs)
         self.add_artist(a)
                 ^^^
         return a

Ie, call add_artist which is a generic method for adding artists to
the axes.

Hope this helps,
JDH

Dear John,

I see your points. However, after I changed to using add_artist. This is still nothing on the canvas. I think that there is some problem with the draw function of my arrow class. I have no idea what else should be there. At the moment, only one call in my case as below.

  def draw(self, renderer):
    self._stem.draw(renderer)

Could u tell what else should be called?

Best regards,
Chris

John Hunter wrote:

···

"Chris" == Chris <biertje@...385...> writes:

    > I tried with what you suggested to make an Arrow class. To
    > begin with, I only put an Line2D instance. I searched for
    > table stuff in axes.py, matlab.py to make the arrow
    > importable from matplotlib.matlab. Then I also try a very
    > very simple demo and I expect to see a simple
    > line. However, I can not see it. Could someone tell me what
    > is the problem. Here is my very very rudimental codes.

Nowhere in your code do you actually draw the arrows in self.arrows.
In Axes.draw you would need to do

    for arrow in self.arrows: arrow.draw(renderer)

And this should work.

However, you can avoid all the overhead of add_arrow, and keeping a
list of arrows in self.arrows simply by doing

     def arrow(self, x, y, *args, **kwargs):
         a = Arrow(x,y, *args, **kwargs)
         self.add_artist(a)
                 ^^^
         return a

Ie, call add_artist which is a generic method for adding artists to
the axes.

Hope this helps,
JDH

-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8