[英]Plotting with multiple Y-axes
使用ax.<plot_function>
在图形上绘制对象时。 如何"hold on"
绘图并在同一绘图上渲染多个绘图?
例如:
f = plt.figure(figsize=(13,6))
ax = f.add_subplot(111)
ax.plot(x1,y1)
ax.plot(x2,y2)
ax.plot(xN,yN)
我尝试添加:
ax.hold(True)
在我开始绘制之前,但是它不起作用。 我认为问题在于它们都共享相同的y比例,而我只看到值范围最大的图。
如何在同一图上绘制多个不同比例的1D数组? 有什么办法可以将它们的Y轴彼此相邻地绘制?
问题中的代码应该没有任何问题:
import matplotlib.pyplot as plt
import numpy as np
# some data
x1 = np.linspace(0, 10, 100)
x2 = np.linspace(1, 11, 100)
xN = np.linspace(4, 5, 100)
y1 = np.random.random(100)
y2 = 0.5 + np.random.random(100)
yN = 1 + np.random.random(100)![enter image description here][1]
# and then the code in the question
f = plt.figure(figsize=(13,6))
ax = f.add_subplot(111)
ax.plot(x1,y1)
ax.plot(x2,y2)
ax.plot(xN,yN)
# save the figure
f.savefig("/tmp/test.png")
创建:
这应该与预期的差不多。 因此,问题不在代码中。
您是否在外壳中运行命令? 哪一个? IPython?
一个大胆的猜测:所有三个图都是图,但是图中的数据对于所有图都是完全相同的,并且它们相互重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.