绘制多个Y轴 [英] Plotting with multiple Y-axes
问题描述
使用ax.<plot_function>
在图形上绘制对象时.我如何"hold on"
情节和
在同一图上绘制多个图?
When using ax.<plot_function>
for plotting objects on a figure. How can I "hold on"
the plot and
render multiple plots on the same plot?
例如:
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轴,而我只能看到值范围最大的图.
before I start plotting, but it doesn't work. I think the problem is that they all share the same y-scale and I only see the plot with the largest range of values.
如何在同一图上绘制多个不同比例的1D数组?有什么办法可以将它们的Y轴彼此相邻地绘制?
How can I plot multiple 1D arrays of different scales on the same plot? Is there any way to plot them with different Y-axis next to each other?
推荐答案
问题中的代码应该没有错:
There should be nothing wrong with the code in the question:
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")
创建:
应该与预期的差不多.因此问题不在代码中.
which should be pretty much what is expected. So the problem is not in the code.
您是否在Shell中运行命令?哪一个? IPython?
Are you running the commands in a shell? Which one? IPython?
一个疯狂的猜测:所有三个图都是图,但是图中的数据对于所有图而言都是完全相同的,并且它们相互重叠.
One wild guess: All three plots are plot, but the data in the plots is exactly the same for all plots, and they overlap each other.
这篇关于绘制多个Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!