From: John H. <jdh...@ac...> - 2004-09-07 02:47:48
|
>>>>> "Alan" == Alan G Isaac <ai...@am...> writes: Alan> I'm a newbie to Matplotlib but a longtime gnuplot user. Alan> Using the matlab module, what is the right way to set Alan> xzeroaxis (using gnuplot terminology). Using axis and hline Alan> seems cumbersome, so I assume there is a better way to Alan> implement this common need. Alan> 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 |