简体   繁体   English

如何在 subplot Python 中反转 y 轴

[英]How to invert y axis in subplot Python

I am trying to make a subplot of three figures.我正在尝试制作三个数字的子图。 All of the figures should have inverted y-axes.所有的图形都应该有倒置的 y 轴。 But when I use ´gca().invert_yaxis()´ it only inverts the last of the three subplots and not the first two.但是当我使用“gca().invert_yaxis()”时,它只会反转三个子图中的最后一个,而不是前两个。 How can I invert all of the y axes?如何反转所有 y 轴?

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()

plt.gca() literally means "get current axes", so it makes sense that only the last one is affected. plt.gca()字面意思是“获取当前轴”,因此只有最后一个受到影响是有道理的。 In your case, the three axes are p1,p2, p3 , therefore p1.invert_yaxis() etc. should do the job.在您的情况下,三个轴是p1,p2, p3 ,因此p1.invert_yaxis()等应该可以完成这项工作。 Delete all lines containing gca() in your code.删除代码中所有包含gca()的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM