How can I multiple plot in one figure at Matlab?

前端 未结 3 1439
猫巷女王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:26

    You need to use 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)
    
    0 讨论(0)
  • 2021-01-25 05:28

    Yes, you can plot everything in one go:

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

    or use hold on after the first call to plot.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题