I am trying to make a subplot of three figures. All of the figures should have inverted y-axes. But when I use ´gca().invert_yaxis()´ it only inverts the last of the three subplots and not the first two. How can I invert all of the y axes?
import matplotlib.pyplot as plt
import pandas
import numpy as np
# Create the subplot
axes,(p1,p2, p3) = plt.subplots(1, 3)
# Temperature proxies
p1.plot(Ti/Mg, xrf_depth)
p1.set_title("Clastic influx (Ti/Mg) and Ti (ppm)")
plt.gca().invert_yaxis()
p2.plot(Ti/1000, xrf_depth)
ax = plt.gca()
p3.plot(Ca/Si, xrf_depth, '-g')
p3.set_title("Primary production (Ca/Si")
plt.show()
CodePudding user response:
plt.gca()
literally means "get current axes", so it makes sense that only the last one is affected. In your case, the three axes are p1,p2, p3
, therefore p1.invert_yaxis()
etc. should do the job. Delete all lines containing gca()
in your code.