[英]Plotting two graphs that share an x-axis in matplotlib
I have to plot 2 graphs in a single screen. 我必须在一个屏幕上绘制2个图表。 The x-axis remains the same but the y-axis should be different.
x轴保持不变,但y轴应该不同。
How can I do that in 'matplotlib'? 我怎么能在'matplotlib'中做到这一点?
twinx
is the function you're looking for; twinx
是您正在寻找的功能; here's an example of how to use it. 这是一个如何使用它的例子 。
subplot
will let you plot more than one figure on the same canvas. subplot
将允许您在同一画布上绘制多个图形。 See the example on the linked documentation page. 请参阅链接文档页面上的示例。
There is an example of a shared axis plot in the examples directory, called shared_axis_demo.py
: 示例目录中有一个共享轴图的示例,名为
shared_axis_demo.py
:
from pylab import *
t = arange(0.01, 5.0, 0.01)
s1 = sin(2*pi*t)
s2 = exp(-t)
s3 = sin(4*pi*t)
ax1 = subplot(311)
plot(t,s1)
setp( ax1.get_xticklabels(), fontsize=6)
## share x only
ax2 = subplot(312, sharex=ax1)
plot(t, s2)
# make these tick labels invisible
setp( ax2.get_xticklabels(), visible=False)
# share x and y
ax3 = subplot(313, sharex=ax1, sharey=ax1)
plot(t, s3)
xlim(0.01,5.0)
show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.