Hello I have made a plot in matplot lib using pandas however I need to swap my x and y axis.
Here is my plot:
broomstick plot

however i need it to look like this:
correct broomstick plot

I'm using a pandas dataframe to plot the data.
I've looked over some documentation and other posts regarding swapping the x and y axis and haven't found any easy way to do this. Here some of my python code:
python code

Any resources or ideas would be greatly appreciated.
Try this. You need to include your y_vals as an additional column. So with this you can just specify your axis here df.plot(x=, y=):
Code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.cos(x)
df = pd.DataFrame({'y': y, 'x': x})
df.plot(x='x')
plt.show()
df.plot(x='y')
plt.show()
Plots:

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