Multiple lines with axhline?

Hi all,

I sometimes find myself wanting to plot a series of lines using
axhline or axvline. Is there a mechanism to do this that I'm missing,
or would it be difficult to support the positional parameter being an
array of values at which to draw each line?

Angus.

···

--
AJC McMorland, PhD candidate
Physiology, University of Auckland

(Nearly) post-doctoral research fellow
Neurobiology, University of Pittsburgh

2008/6/27 Angus McMorland <amcmorl@...287...>:

Hi all,

I sometimes find myself wanting to plot a series of lines using
axhline or axvline. Is there a mechanism to do this that I'm missing,
or would it be difficult to support the positional parameter being an
array of values at which to draw each line?

In fact, I see it does work... sort of. For me, with 0.91.2-2 (debian)
asking axhline throws up an error:

/usr/lib/python2.5/site-packages/matplotlib/pyplot.pyc in
axvline(*args, **kwargs)
   1358 hold(h)
   1359 try:
-> 1360 ret = gca().axvline(*args, **kwargs)
   1361 draw_if_interactive()
   1362 except:

/usr/lib/python2.5/site-packages/matplotlib/axes.pyc in axvline(self,
x, ymin, ymax, **kwargs)
   2330
   2331 trans = mtrans.blend_xy_sep_transform( self.transData,
self.transAxes )
-> 2332 l, = self.plot([x,x], [ymin,ymax] , transform=trans,
scaley=False, **kwargs)
   2333 return l
   2334

and doesn't immediately update the plot (which is what had me thinking
it wasn't working). The plot is, however, correctly updated when a
redraw is forced, such as uncovering the window after writing the
previous email.

···

Angus.
--
AJC McMorland, PhD candidate
Physiology, University of Auckland

(Nearly) post-doctoral research fellow
Neurobiology, University of Pittsburgh

--
AJC McMorland, PhD candidate
Physiology, University of Auckland

(Nearly) post-doctoral research fellow
Neurobiology, University of Pittsburgh

You could use a line collection with the right transform

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib.collections as collections

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10))

trans = mtransforms.blended_transform_factory(
            ax.axes.transData, ax.axes.transAxes)
coll = collections.LineCollection([((x, 0), (x, 1)) for x in
10*np.random.rand(20)],
                                  transform=trans, color='red', lw=2, alpha=0.5)
ax.add_collection(coll)

plt.show()

···

On Fri, Jun 27, 2008 at 2:56 PM, Angus McMorland <amcmorl@...287...> wrote:

Hi all,

I sometimes find myself wanting to plot a series of lines using
axhline or axvline. Is there a mechanism to do this that I'm missing,
or would it be difficult to support the positional parameter being an
array of values at which to draw each line?