10

我必须在一个屏幕上绘制 2 个图表。x 轴保持不变,但 y 轴应该不同。

我怎么能在'matplotlib'中做到这一点?

4

2 回答 2

19

twinx是您要查找的功能;这是一个如何使用它的例子。

孪生示例

于 2009-09-10T10:50:20.577 回答
7

subplot将让您在同一画布上绘制多个图形。请参阅链接文档页面上的示例。

在示例目录中有一个共享轴图的示例,名为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() 
于 2009-09-10T10:45:00.827 回答