plotting a matplotlib.lines.Line2D instance directly

Hi everybody,

In my own application, I want to specialize matplotlib.lines.Line2D to be
able to deal with units.
Concerning this class, is there a direct means to plot instances?

For example, if I do:

a=matplotlib.lines.Line2D([5,6],[7,8],color='m')

To plot it, I have not found another way than doing:

plot(a.get_xdata(), a.get_ydata())

But it is clumsy, because if I want to keep the line color:

plot(a.get_xdata(), a.get_ydata(), a.get_color())

And so on for marker style, etc.

Is there a direct means to plot a Line2D instance?

Some time ago, a colleague wrote a "Curve_2D" class from scratch, to store a
2D curve, independently from matplotlib. Instead of that, I would like to be
able to specialize Line2D matplotlib class.

Am I compelled to write a .plot() method to Line2D?

In other words, when I do:

a=plot((1,2),(2,3),'r--')

I obtain a Line2D instance:

a[0]

<matplotlib.lines.Line2D instance at 0x954d08c>

I would like to do the contrary: define a Line2D instance, and then plot
this Line2D. The goal is to avoid re-inventing the wheel in my application,
as did my colleague.

Thanks a lot for your help

Julien

···

--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

You can add it directly to the Axes/Subplot instance with

    ax.add_line(a)

See also the http://matplotlib.sourceforge.net/examples/pylab_examples/clippedline.html
example which shows how to create a custom, derived line class.

JDH

···

On Sat, Nov 29, 2008 at 6:48 AM, TP <paratribulations@...185...> wrote:

Hi everybody,

In my own application, I want to specialize matplotlib.lines.Line2D to be
able to deal with units.
Concerning this class, is there a direct means to plot instances?

For example, if I do:

a=matplotlib.lines.Line2D([5,6],[7,8],color='m')

There must be. I have not done this, but looking at
http://matplotlib.sourceforge.net/api/artist_api.html#module-matplotlib.lines
it looks like you can set the ``axes`` property and looking at the base class
http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.artist.Artist
there is a ``draw`` method.

hth,
Alan Isaac

···

On 11/29/2008 7:48 AM TP apparently wrote:

In my own application, I want to specialize matplotlib.lines.Line2D to be
able to deal with units.
Concerning this class, is there a direct means to plot instances?