Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python matplotlib: way to transpose axes

Tags:

matplotlib

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 y-axis and vice-versa? Or even the axes before the plot so that the plotting function just does everything correctly (labeling) by relying on the axes functions?

I know how to do this "manually", but I'm wondering if there is a slightly hidden level of abstraction that allows this kind of transformation.

like image 287
mathtick Avatar asked Apr 02 '13 15:04

mathtick


People also ask

How do I flip axes in matplotlib?

In Matplotlib we can reverse axes of a graph using multiple methods. Most common method is by using invert_xaxis() and invert_yaxis() for the axes objects. Other than that we can also use xlim() and ylim(), and axis() methods for the pyplot object.

How do I customize Xticks in matplotlib?

Set the figure size and adjust the padding between and around the subplots. Create lists for height, bars and y_pos data points. Make a bar plot using bar() method. To customize X-axis ticks, we can use tick_params() method, with color=red, direction=outward, length=7, and width=2.

What does %Matplotlib do in Python?

Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.


1 Answers

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())
like image 196
tacaswell Avatar answered Sep 23 '22 17:09

tacaswell