1

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.

4
  • There is plt.fill_betweenx. I'm not sure there is a general way that will swap the axis, though... Commented Apr 17, 2019 at 13:01
  • 1
    you can use fill_betweenx instead of fill_between. What "other similar issues" do you encounter? Commented Apr 17, 2019 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. Commented Apr 17, 2019 at 13:30
  • the keyword to look for is transpose. maybe this entry helps? stackoverflow.com/questions/15767781/… Commented Apr 17, 2019 at 13:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.