 # xzeroaxis

I'm a newbie to Matplotlib but a longtime gnuplot user.

> Using the matlab module, what is the right way to set
> xzeroaxis (using gnuplot terminology). Using axis and hline
> seems cumbersome, so I assume there is a better way to
> implement this common need.

> Thank you, Alan Isaac

I've not used set xzeroaxis. I googled around a bit and gathered that
this draws a horizontal line from xmin to xmax at y=0. There is not
equivalent currently in matplotlib so there is no clean and easy way
to do this, but Fernando Perez and I talked a bit at scipy about
adding some gnuplot compatibility functions and this would fit under
that umbrella. I'm interested in getting some feedback about whether
folks think this is a good idea. The worry is that we dump too much
into the axes to support matlab, IDL and gnuplot users.

Here's how you should do this under the current matplotlib. What you
want to do is plot a line where the y coord is in data units and equal
to zero, and the x coord is in axes units and spans the xrange. The
line stretches from left to right regardless of the xlimits.

Each axes provides a data transform and an axes transform, so that you
can specify lines/text/etc in either coord system; axes coords are 0,0
for lower left and 1,1 for upper right. But what you want to do is
mix the data and axes transforms for x and y. The transforms module
provides a helper function for this. The following code is freestyle
(untested) but should work

from matplotlib.transforms import blend_xy_sep_transform

ax = gca()
trans = blend_xy_sep_transform( ax.transAxes, ax.transData)
plot([0,1], [0,0], transform=trans)

Try this out and see if it behaves as you like. I can add a methods
for this for xzero and yzero if you and others feel this would be
useful. Rather than reusing the gnuplot names, it might be better to
provide a method that always draws a line from xmin to xmax at a given
height regardless of the xlim, and do the same for a vertical line at
some x.

JDH

I've not used set xzeroaxis. I googled around a bit and gathered that
this draws a horizontal line from xmin to xmax at y=0.

Right.

Fernando Perez and I talked a bit at scipy about
adding some gnuplot compatibility functions and this would fit under
that umbrella. I'm interested in getting some feedback about whether
folks think this is a good idea.

I care about functionality much more than syntax.
This is a common need, so it shd be easy to do.

from matplotlib.transforms import blend_xy_sep_transform
ax = gca()
trans = blend_xy_sep_transform( ax.transAxes, ax.transData)
plot([0,1], [0,0], transform=trans)
Try this out and see if it behaves as you like.

So far so good.

Rather than reusing the gnuplot names, it might be better to
provide a method that always draws a line from xmin to xmax at a given
height regardless of the xlim, and do the same for a vertical line at
some x.

I agree. I actually need the additional functionality.

So while we're generalizing let me dream. Focus on the case
of vertical lines. The ideal functionality would allow me
to use 'vlines' with a special value to indicate ymin and
ymax. Ideally this same 'special values' convention would
extend to 'fill' (or maybe 'bar'), since I often need event
shading. Perhaps the obvious special value is None?

fwiw,
Alan

···

On Mon, 06 Sep 2004, John Hunter apparently wrote: