0

Is there a one-liner or a short, elegant solution to flip the data and the labels of a figure? Something like fig.swapaxes(swap=true). This function should make the first plot look like the second one.

import numpy as np
import matplotlib.pyplot as plt

height = np.linspace(40,100,100)
weight = 3.0*height

######################## First Plot #####################
fig = plt.figure()
ax  = fig.gca()
ax.plot(height,weight)
ax.set_xlabel('height')
ax.set_ylabel('weight')

## Is there a one-liner or a short, elegant solution to flip 
## the data and the labels? something like fig.swapaxes(swap=true)
## this function should make the first plot look like the second one
##
################ Second Plot ###########################
fig = plt.figure()
ax  = fig.gca()
ax.plot(weight,height)
ax.set_xlabel('weight')
ax.set_ylabel('height')
NNN
  • 697
  • 1
  • 5
  • 15
  • Does this answer your question? [How to switch axes in matplotlib?](https://stackoverflow.com/questions/2361872/how-to-switch-axes-in-matplotlib) – Ofer Sadan Aug 22 '22 at 11:34
  • Nope. I was looking for something more elegant. – NNN Aug 22 '22 at 11:48

0 Answers0