Carter
Carter

Reputation: 274

How can I multiple plot in one figure at Matlab?

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?

Upvotes: 1

Views: 2006

Answers (3)

Rogue
Rogue

Reputation: 56

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.

Upvotes: 2

GPPK
GPPK

Reputation: 6666

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)

Upvotes: 2

am304
am304

Reputation: 13886

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.

Upvotes: 2

Related Questions