Different coloured regions on a scatter plot

I have a g-g diagram where I want to display different regions in different colours (so right acceleration is one colour, pure acceleration is a different one, left acceleration is different, pure left cornering is different and so on). I was able to overlay a plot on top to show left, right and in the middle like this:
sz = 8
scatter(Lat_A, Long_A, sz, 'filled')
ylabel("Longitudinal Acceleration /g")
xlabel("Lateral Acceleration /g")
threshold = 0.4
right = Lat_A(Lat_A>threshold)
left = Lat_A(Lat_A<-threshold)
hold on;
scatter(right, Long_A(Lat_A > threshold), sz, 'g', 'filled');
scatter(left, Long_A(Lat_A < -threshold), sz, 'r', 'filled');
hold off;
However, I'm struggling to factor in the braking and acceleration the same way on the same plot. In simple terms, I want to show (x>0.4, y>0.4), (x<-0.4, y>0.4), (abs(x)< 0.4, y>0.4) etc. as different colours. I'm pretty new to MATLAB so any help would be appreciated.

Answers (2)

Depicting regions such as: '(x>0.4, y>0.4), (x<-0.4, y>0.4), (abs(x)< 0.4, y>0.4) etc.' would require a patch plot. These can be overlaid with your current plot, however it would be best to change the 'FaceAlpha' property to something less than 1 in order to show the other data clearly. (I had to look up 'g-g diagram.)
I am not certain what you want to do, however something like this could work --
figure
patch([-4 0 0 4], [4 0 0 4], 'g', FaceAlpha=0.5, EdgeColor='none')
axis([-5 5 -1 5])
grid
The patch arguments have to describe a closed region, so at least 4 values for each one.
.

2 Comments

Felicity
Felicity about 1 hour ago
Edited: Felicity 43 minutes ago
Sorry I forget not everyone is a motorsport nerd. To put it in context, I'm doing an analysis to see lateral vs longitudinal acceleration recorded by a race car over the course of 1 lap of a circuit.
This is an image of a different one I found online that I think illustrates what I want a bit better (although I don't need the lines around or between the colours, just colouring the points would be enough). The only thing is I want to have the points in each region stored somehow so I can then see how many fall within each region. That way I can see what % of the lap time was spent doing each activity.
Thank you very much for the response, I'll have a play around with your suggestions.
Airplanes for me. I'm an Instrument-Rated Private Pilot, so cars only to get to and from the airport!
'The only thing is I want to have the points in each region stored somehow so I can then see how many fall within each region
See if the inpolygon function does what you want. (I'm still not absolutely certain what that is.)
For the region colours, I still recommend patch.
EDIT -- (11 Sep 2026 at 00:23)
Using inpolygon to determine the points inside and outside a region, then plotting them --
t = linspace(0, 2*pi, 500).';
r = 1;
c = r.*[cos(t) sin(t)];
datax = randn(250,1);
datay = randn(250,1);
[in,on] = inpolygon(datax, datay, c(:,1), c(:,2));
nron = nnz(on)
nron = 0
figure
plot(c(:,1), c(:,2), DisplayName='Region of Interest')
hold on
scatter(datax(in), datay(in), '.g', DisplayName='In Region')
scatter(datax(~in), datay(~in), '.r', DisplayName='Outside of Region')
if nron ~= 0
scatter(datax(on), datay(on), '.m', DisplayName='On Border')
end
hold off
grid
axis('equal')
xlabel('X')
ylabel('Y')
legend(Location='best')
pctpoints = nnz(in)/size(datax,1) * 100;
title(sprintf('Region Contains %.2f%% Of The Data',pctpoints))
.

Sign in to comment.

"just colouring the points would be enough" <== One of the inputs to scatter is a vector of colors that you want each marker point to have.
help scatter
scatter - Scatter plot Syntax Vector and Matrix Data scatter(x,y) scatter(x,y,sz) scatter(x,y,sz,c) scatter(___,"filled") scatter(___,mkr) Table Data scatter(tbl,xvar,yvar) scatter(tbl,xvar,yvar,"filled") Additional Options scatter(ax,___) scatter(___,Name,Value) s = scatter(___) Input Arguments x - x-coordinates scalar | vector | matrix y - y-coordinates scalar | vector | matrix sz - Marker size 36 (default) | numeric scalar | row or column vector | matrix | [] c - Marker color color name | RGB triplet | matrix of RGB triplets | vector of colormap indices mkr - Marker symbol "o" (default) | "+" | "*" | "." | "x" | ... "filled" - Option to fill interior of markers "filled" tbl - Source table table | timetable xvar - Table variables containing x-coordinates one or more table variable indices yvar - Table variables containing y-coordinates one or more table variable indices ax - Target axes Axes object | PolarAxes object | GeographicAxes object Name-Value Arguments MarkerEdgeColor - Marker outline color "flat" (default) | RGB triplet | hexadecimal color code | "r" | "g" | "b" | ... MarkerFaceColor - Marker fill color "none" (default) | "flat" | "auto" | RGB triplet | hexadecimal color code | "r" | "g" | "b" | ... LineWidth - Width of marker edge 0.5 (default) | positive value ColorVariable - Table variable containing color data table variable index Output Arguments s - Scatter object Scatter object | array of Scatter objects Examples openExample('graphics/CreateScatterPlotExample') openExample('graphics/VaryCircleSizeExample') openExample('graphics/VaryCircleColorExample') openExample('graphics/ScatterColorPaletteExample') openExample('graphics/VaryCircleSizeandColorExample') openExample('graphics/SpecifyMarkerSymbolExample') openExample('graphics/SpecifyMarkerPropertiesExample') openExample('graphics/ScatterAlphaDataExample') openExample('graphics/ScatterTableExample') openExample('graphics/ScatterTableSizeColorExample') openExample('graphics/ScatterSpecifyAxes19bExample') openExample('graphics2/SetScatterObjectPropertiesExample') See also hold, plot, scatter3, bubblechart, swarmchart, Scatter Properties Introduced in MATLAB before R2006a Documentation for scatter doc scatter Other uses of scatter tall/scatter

Products

Release

R2026a

Asked:

on 10 Sep 2026 at 10:47

Edited:

on 11 Sep 2026 at 0:23

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!