0

I would like to create a plot where the independent variable is on the vertical axis, or expressed differently, where the x-axis is vertical. The reason is that the x-axis represents depth.

Say I have the depths stored in x, and the dependent variable stored in y

I know that I can achieve this for a single line using the matplotlib function plt.plot(y,x) instead of plt.plot(x,y)

However, this creates secondary issues with parameters that are usually defined on the dependent variables. For example, I don't know how I could then plot error ranges, as shown in the code below.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 11) 
y = np.linspace(2, 3, 11)
ymax = y+1;
ymin = y-1;
plt.figure()
plt.plot(x,y)
plt.fill_between(x,ymin,ymax, facecolor='blue', alpha=0.5)

Note that I am not looking for a workaround to plot error ranges on the independent variable, because that will not solve other similar issues.

MS11
  • 23
  • 3
  • There is `plt.fill_betweenx`. I'm not sure there is a general way that will swap the axis, though... – Graipher Apr 17 '19 at 13:01
  • 1
    you can use [`fill_betweenx`](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.fill_betweenx.html#matplotlib.pyplot.fill_betweenx) instead of `fill_between`. What "other similar issues" do you encounter? – ImportanceOfBeingErnest Apr 17 '19 at 13:02
  • There can be issues with anything where the independent and dependent variables are not treated equally. For example, if you want to plot a stem plot, the stems will always be towards the axis of the independent variable. – MS11 Apr 17 '19 at 13:30
  • the keyword to look for is transpose. maybe this entry helps? https://stackoverflow.com/questions/15767781/python-matplotlib-way-to-transpose-axes – warped Apr 17 '19 at 13:46

0 Answers0