Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB - Plot multiple data sets on a scatter plot

Tags:

I have two sets of data, (Ax, Ay; Bx, By). I'd like to plot both of these data sets on a scatter plot with different colors, but I can't seem to get it to work, because it seems scatter() does not work like plot(). Is it possible to do this?

I've tried...

scatter(Ax, Ay, 'g', Bx, By, 'b') 

And

scatter(Ax, Ay, 'g') scatter(Bx, By, 'b') 

The first way returns an error. The latter only plots the Bx/By data.

like image 737
Mark Avatar asked Mar 20 '10 02:03

Mark


People also ask

How do you plot multiple data on one graph in Matlab?

Create Plot Spanning Multiple Rows or Columns To create a plot that spans multiple rows or columns, specify the span argument when you call nexttile . For example, create a 2-by-2 layout. Plot into the first two tiles. Then create a plot that spans one row and two columns.

Which Matlab command is used to be able to plot two data sets on the same plot?

Use hold on and hold off to add new data to a set of existing Axes.

How do you plot multiple XY in Matlab?

For example, you can create two plots that have different x- and y-axis limits. First, create two sets of x- and y-coordinates. x1 = 0:0.1:40; y1 = 4. *cos(x1)./(x1+2); x2 = 1:0.2:20; y2 = x2.


2 Answers

Try using hold on with the second example.

like image 82
Qtax Avatar answered Sep 22 '22 18:09

Qtax


plot (ax,ay,'g.') generates a scatter plot with green dots

if you want bigger circles, you can use

plot (ax,ay,'g.', 'MarkerSize', XX) %XX = 20 or whatever

To make open circles

plot (ax, ay, 'go')

As you know, plot can be chained, so you can do it one go with

plot (ax, ay, 'go', bx, by, 'bo')

The difference between plot and scatter is that scatter lets you specify the marker size, but you're not asking to do that here.

like image 37
Marc Avatar answered Sep 22 '22 18:09

Marc