我怎样才能在 Matlab 的一个图中绘制多个图?

How can I multiple plot in one figure at Matlab?

您好,我正在尝试按以下代码实现。

plot(bins,r);
plot(bins,g);
plot(bins,b);

但是我想在一个图中绘制。 有什么办法吗?

是的,您可以一次绘制所有内容:

plot(bins,r,bins,g,bins,b)

或在第一次调用 plot 后使用 hold on

您需要使用hold on

hold on retains plots in the current axes so that new plots added to the axes do not delete existing plots. New plots use the next colors and line styles based on the ColorOrder and LineStyleOrder properties of the axes. MATLAB® adjusts axes limits, tick marks, and tick labels to display the full range of data.

hold on
plot(bins,r)
plot(bins,g)
plot(bins,b)

对于同一张图中的多个绘图而不是同一个轴。你必须使用子图(x,y,z)。第一个参数 'x' 是你想要生成的图的数量,在你的例子中是 3。第二个 'y' 只是调整图的大小,你可以使用 1。第三个 'z' 是情节的位置,某个情节是第一,第二还是第三。

subplot(3,1,1)
plot(bins,r);
subplot(3,1,2)
plot(bins,g);
subplot(3,1,3)
plot(bins,g);

要区分所有三个绘图,您可以向 plot() 添加另一个参数,以便您可以更改颜色。例如:

plot(bins,r,'r')

'r' 将使绘图的颜色变为红色,'b' 使其变为蓝色,'k' 使其变为黑色...依此类推。