How can I multiple plot in one figure at Matlab?

前端 未结 3 1438
猫巷女王i
猫巷女王i 2021-01-25 04:56

Hi I\'m trying to implement as following code.

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

But I want to plot in one figure. Is there any way?

3条回答
  •  情歌与酒
    2021-01-25 05:44

    For multiple plots in the same figure and not the same axis. You have to use subplot(x,y,z). The first argument 'x' is the number of plot you want to produce, in your case 3. Second 'y' just adjusts the size of the plots, you can use 1. The third 'z' is the position of the plot, whether a certain plot comes first, second or third.

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

    To distinguish between all three plot you can add another argument to plot() so that you can change colors. For example:

    plot(bins,r,'r')
    

    'r' will make the color of the plot red, 'b' makes it blue, 'k' makes it black...so on.

提交回复
热议问题