简体   繁体   English

在所有子图中使用次要连续y轴绘制子图

[英]Plotting subplots with secondary continuous y-axis across all subplots

I have a numpy arrays of temperature, wind speed, heat flux etc. Each of these arrays is assigned to its own subplot. 我有一个数不清的温度,风速,热通量等数组。每个数组都分配给自己的子图。 The snow depth I would like to be plotted on the combined area of the subplots. 我想将雪深绘制在子图的组合区域上。 As if the second y-axis is of one plot. 好像第二个y轴是一个图。

In the attached image is what I would like to create 我要在附件中创建图像 样例 . One can see the snow depth is on the secondary y-axis. 可以看到降雪深度在辅助y轴上。

You can use twinx() to create a second y-axis that shares the same x-axis 您可以使用twinx()创建共享相同x轴的第二个y轴

ax1 = axes()
ax2 = ax1.twinx()

x = np.arange(100)
y1 = np.random.rand(100)
y2 = np.random.rand(100)

ax1.plot(x,y1,'-r')
ax1.set_ylim(-1,1)
ax2.fill_between(x,0,y2,color='b',alpha=0.5)
ax2.set_ylim(0,2)

ax1.set_ylabel('Red')
ax2.set_ylabel('Blue')

在此处输入图片说明

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

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