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.
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.
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.
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.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With