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)

回答(2 个)

Cris LaPierre
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');
  1 个评论
義典 鈴木
義典 鈴木 2021-12-16
Thank you for the reply. I already tried this but nothing changes. I guess there is something wrong in the code I wrote in the app

请先登录,再进行评论。


Image Analyst
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)
Error using uicontrol
This functionality is not available on remote platforms.

Error in rotate3d>localCreateAzElIndicator (line 478)
rdata.ModeStateData.textBoxText = uicontrol('Parent',hFig,'Units','Pixels',...

Error in rotate3d>localDoRotateOn (line 508)
localCreateAzElIndicator(rdata)

Error in rotate3d>@(~,~)localDoRotateOn(rdata) (line 393)
set(rdata,'ModeStartFcn',@(~,~)localDoRotateOn(rdata));

Error in hgfeval (line 62)
feval(fcn{1},varargin{:},fcn{2:end});

Error in matlab.uitools.internal.uimode/modeControl (line 16)
hgfeval(hThis.ModeStartFcn);

Error in matlab.uitools.internal.uimode/set.Enable (line 167)
obj.Enable = modeControl(obj,value);

Error in matlab.uitools.internal.uimodemanager>localSetMode (line 200)
set(newMode,'Enable','on');

Error in matlab.uitools.internal.uimodemanager/set.CurrentMode (line 119)
obj.CurrentMode = localSetMode(obj,value);

Error in activateuimode (line 30)
set(hManager,'CurrentMode',hMode);

Error in rotate3d>setState (line 363)
activateuimode(fig,'Exploration.Rotate3d');

Error in rotate3d (line 262)
setState(hTarget,arg2,rotatestyle)

Error in colorcloud>setAxesProperties (line 205)
rotate3d(hAx,'on');

Error in colorcloud (line 121)
setAxesProperties(hPanel,hAx,options);
  2 个评论
義典 鈴木
義典 鈴木 2021-12-16
Thank you. I am actually doing color analysis and I want to plot the main color in the a-b graph. I want to plot the coordinates with the color responding to the analysis. For example,
a =[2,3,6,3,6,9]
b =[1,5,6,7,5,4]
c =[0.1 0.4 0.5
0.4 0.6 0.8
0.5 0.8 0.2
0.3 0.1 0.6
0.7 0.8 0.9
0.5 0.3 0.3
]
but the problem is I am using app designer and I use mat file to store the data

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by