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

25 views (last 30 days)
taimour sadiq
taimour sadiq on 20 Oct 2020
Commented: Adam Danz on 26 Mar 2021
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.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
on "UIAxes" when i double click and assign any colour to first plot then any second colour to other plot.... Kindly Guide.
taimour sadiq
taimour sadiq on 21 Oct 2020
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.M = plot(app.UIAxes,a,b,"Color",mycolour);
elseif app.SCheckBox.Value && ~app.LCheckBox.Value
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);
app.M = plot(app.UIAxes,a,c,"Color",mycolour);
app.M.Visible = 'off';

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 20 Oct 2020
Edited: Adam Danz on 20 Oct 2020
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by