Suppose I have a plotting function that takes an axes argument (or returns one). Is there some low-level method for transposing the whole plot so that the x-axis becomes the
An old post (circa 2005) to the mailing list from John Hunter. I suspect that this a rare enough of a desire and tricky enough to do that it has not been added sense then.
John Hunter's example for swapping axes on an existing plot was
line2d = plot(rand(10))[0]
def swap(xdata, ydata):
line2d.set_xdata(ydata)
line2d.set_ydata(xdata)
draw()
swap(line2d.get_xdata(), line2d.get_ydata())
Not more than a wrap for tcaswell's answer.
def swap(*line_list):
"""
Example
-------
line = plot(linspace(0, 2, 10), rand(10))
swap(line)
"""
for lines in line_list:
try:
iter(lines)
except:
lines = [lines]
for line in lines:
xdata, ydata = line.get_xdata(), line.get_ydata()
line.set_xdata(ydata)
line.set_ydata(xdata)
line.axes.autoscale_view()
An example
line = plot(linspace(0, 2, 10), rand(10))
swap(line)