How to draw a straight line?

kc106_2005-matplotlib@...9... writes:

How do I draw a line going from point A to point B on a figure (not
plot reference frame), with a particular color and style?

Give a transform=gcf().transFigure argument to plot:
http://www.scipy.org/Cookbook/Matplotlib/Transformations

If your line goes outside the axes, you will want to do something like

l=plot([...], [...], transform=gcf().transFigure)
setp(l, clip_on=False)

For some reason the clip_on keyword argument to plot does not have an
effect. This is probably a bug.

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks

It probably makes more sense not to use Axes.plot at all, since the
line is not associated with an Axes

from matplotlib.lines import Line2D
from pylab import figure, show, nx

fig = figure()
line = Line2D([100,200,300,400,500], [100,400, 350, 200, 500],
              linewidth=4, color='green')
fig.lines.append(line)
show()

But this feature isn't used very much, and one thing that we are not
currently supporting (but should) is the zorder for Artists in the
Figure. So if you have an Axes in your plot and you want the line to
go over it, you'll need to do something like Jouni suggested so the
line will be drawn above the Axes.

···

On 3/6/07, Jouni K. Seppänen <jks@...397...> wrote:

kc106_2005-matplotlib@...9... writes:
> How do I draw a line going from point A to point B on a figure (not