How to scatter plot using different colors by using own RGB data?
11 views (last 30 days)
Show older comments
I`m using Matlab App Designer to create a scatter plot and I want to use my own rgb data for the colors but I think my code is wrong somewhere.
Style = app.SelectedStyles;
Colors = app.SelectedColors;
% Start with a fresh plot
cla(app.UIAxes)
hold(app.UIAxes,'on')
% Select relevant segment of data
xdata = app.Data.a;
ydata = app.Data.b;
cdata = app.Data.c;
%cdata = app.Data.c;
% Filter the data according to the controls
filterData(app);
% Build a scatter plot for each selected style
for ii = 1:length(Style)
selectedstyles = ((app.Data.styles == Style(ii)) & (app.displayedIndices));
selectedcolors = ((app.Data.c == Colors(ii)) & (app.displayedIndices));
scatter(app.UIAxes,xdata((selectedstyles)),ydata(selectedstyles),cdata(selectedcolors),'filled','s');
end
annotateScatterPlot(app)
% Update the table to show only the data that satisfies the controls
app.UITable.Data = app.Data(app.displayedIndices,:);
drawnow;
% List which styles and colors to use
Style = [];
Colors = [];
if app.JapaneseCheckBox.Value
Style = "japanese";
Colors = [];
end
if app.AfricanCheckBox.Value
Style = [Style "African"];
Colors = [];
end
app.SelectedStyles = Style;
app.SelectedColors = Colors;
refreshplot(app)
0 Comments
Answers (2)
Cris LaPierre
on 10 Nov 2021
Color is the 4th input to scatter.
You have placed it in the 3rd spot, which is for size. What happens if you try this?
scatter(app.UIAxes,xdata((selectedstyles)),ydata(selectedstyles),[],cdata(selectedcolors),'filled','s');
Image Analyst
on 11 Nov 2021
If you use the built-in colorcloud() function, does that do what you want? (Ignore the red junk after the image).
img = imread('peppers.png');
colorcloud(img)
2 Comments
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!