How to scatter plot using different colors by using own RGB data?
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Cris LaPierre
2021-11-10
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
2021-11-11
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!