how to assign colour to a double plot by clicking on graph in UIAxes appdesinger Matlab (R2020a)?

hello, my objective is to assign different colour to a double plot of own choice. if i have three variable data...
a= [1 2 3]
b = [4 5 7]
c = [7 8 9]
plot(a,b);
hold(app.UIAxes,'on')
plot (a.c)
% this will give us double plot... now one way to assign colour to plot is >>> plot(a,b,"color",'red') and plot(a,c,"color",'blue').
% second way is to throug "drop down" for example >>> SelectColour = app.dropdown.Value and then use plot(a,b,"colour",'SelectedColout')... with above two ways i succesfully assigned colour....
% third is to use default colour sequence... but i want user selected colour for every plot.
The above was just to show that i made effort but in first case we cannot change colour and in second case it changes colour for every graph. it should be coded such it saves colour assigned then assign next colour via dropdown
or
on "UIAxes" when i double click and assign any colour to first plot then any second colour to other plot.... Kindly Guide.

2 Comments

What release of Matlab are you using?
Do be clear, you want the user to be able to select a color for each line independently, is that correct?
Do you have a list of colors in mind?
Why doesn't your method #2 work? Could you share that part of the code? It will probably be easy to fix.
Thanks Adam for ur Reply... yes i want the user to be able to select a color for each line independently i m using R202a and colour could be any or lets say 'red' & Blue. Yes second choice is working but when i double plot it changes same. colour for both plots
i was using the code
function plotwidth(app)
a = 0:0.1:2*pi;
b = sin(a);
c = cos(a);
mycolour = app.SelectedColourDropDown.Value;
if app.LCheckBox.Value && ~app.SCheckBox.Value
app.UIAxes.cla;
app.M = plot(app.UIAxes,a,b,"Color",mycolour);
elseif app.SCheckBox.Value && ~app.LCheckBox.Value
app.UIAxes.cla;
app.M = plot(app.UIAxes,a,c,"Color",mycolour);
elseif app.LCheckBox.Value && app.SCheckBox.Value
app.N = plot(app.UIAxes,a,b,"Color",mycolour);
hold(app.UIAxes,"on");
app.M = plot(app.UIAxes,a,c,"Color",mycolour);
hold(app.UIAxes,"off");
else
app.M.Visible = 'off';
end
end

Sign in to comment.

 Accepted Answer

Line color can be changed when the figure is in Edit-plot mode by right-clicking on the line which shows the lines context menu and then by selecting Color (Matlab R2020B).
To turn on PlotEdit,
uif = uifigure();
uiax = uiaxes(uif);
plot(uiax, rand(5,3)); % add some lines
% Turn on plot-edit
% This can be placed in a callback function to toggle on/off
plotedit(uif,'on') % 'off' to turn off
now right-click on a line

8 Comments

Adam this is what i exactly wanted that we should clik on a line and perform multiple task like assigning colour, line width etc ... Much thanks
kindly guide me how to use existing app.UIAxes instead of creating new figure...
i tried
a = 0:0.1:2*pi;
b = sin(a);
plot(app.UIAxes,a,b));
plotedit(uif,'on');
but i still open new empty figure and also UIAes window but option also not show for colour selecting etc... i think i m not propertly defining code syntax.. kindly Guide my complete code file is also attached i above comment. Dear Adam once again Thanks for ur support.
i m suprised that ur writen code is displaying the output plot but when i click on line no option shows for colour and width as shown in ur screenshots...may be some extra code required...
uif = uifigure();
uiax = uiaxes(uif);
plot(uiax, rand(5,3)); % add some lines
% Turn on plot-edit
% This can be placed in a callback function to toggle on/off
plotedit(uif,'on') % 'off' to turn off
...
i will be gratefull if u guide me how to use plotedit with UIAxes instead of new figure
Support for plotedit in uifigures may have become available in r2020b.
If you cannot upgrade, you can use your existing dropdown list. To help you fix the issues you're having with that, I need to know two things.
1). How you're plotting the lines (just show me the plotting code and describe the variable size).
2) How you're assigning the colors (just show me the callback function to the drop down menu).
Dear Adam Best Regard, i m using single line code both for plot and assigning colour as shown below.
a = 0:0.1:2*pi;
b = sin(a);
mycolour = app.SelectedColourDropDown.Value;
if app.LCheckBox.Value && ~app.SCheckBox.Value
plot(app.UIAxes,a,b,"Color",mycolour);
end
i have placed all code in a function and in every callback wrote that function name.
Your question states that you're plotting two lines but the example above only addresses 1 line.
All you need to do is change the color of the line - not re-plot it.
When you plot the two lines, store their handles in the app (instructions).
In your SelectedColourDropDown function, use those handles to change the colors of the lines. For example, if you named the line handles h1 and h2,
app.h1.Color = mycolour1;
app.h2.Color = mycolour2;
I forget if you can click on a line to make it active in app designer r2020a. If you can, then you can use,
set(gco, 'Color', mycolour)
otherrwise, you'll need to have some way to select which line the color applies to. You could have two color dropdown menus or you could have a 2nd menu that list Line1, Line2.
ok i will read this instruction and learn how to use handles... will update you tommorow because i m not well familiar with handles... Thanks
Hello... Dear Adam ur Guidence helpled me alot.. ur guided command"Plotedit" worked for me and fullfill my requirement as i desired... Thanks Alot..

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Programmatically 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!