How to edit colors for the line?
2 views (last 30 days)
Show older comments
Yingyi Huang
on 5 Aug 2020
Commented: Yingyi Huang
on 6 Aug 2020
The legend line corlor is wrong. How do I change the black to green for the measured one?
0 Comments
Accepted Answer
Walter Roberson
on 5 Aug 2020
We do not know exactly what PlotCone does, but we can predict from the observed behavior that it is creating more than one line() object when it is invoked.
If it can return the line handles, then use
h1 = PlotCone([2000,100,780,50,'k');
h2 = PlotCone(height, Thickness, InnerTopDia, InnerBotDia, [0 0.6 0]);
legend([h1(1), h2(1)], {'Spec', 'Measure'});
3 Comments
Walter Roberson
on 6 Aug 2020
ax = gca;
ch0 = get(ax,'Children');
PlotCone(2000,100,780,50,'black');
ch1 = get(ax,'Children');
hold(ax, 'on');
PlotCone(1916,90.6,796.7,88.8,[0 0.6 0]);
ch2 = get(ax, 'Children')
hold(ax, 'off');
pc1_obj = setdiff(ch1, ch0);
pc2_obj = setdiff(ch2, ch1);
pc1_line = findobj(pc1_obj, 'type', 'line');
if isempty(pc1_line)
pc1_line = pc1_obj(1);
else
pc1_line = pc1_line(1);
end
pc2_line = findobj(pc2_obj, 'type', 'line');
if isempty(pc2_line)
pc2_line = pc2_obj(1);
else
pc2_line = pc2_line(1);
end
legend([pc1_line, pc2_line], {'Spec','Measure'})
Because we as outside observers who do not have access to the source code for PlotCone even though we asked for it, do not know what kind of objects PlotCone generates, we have to take the set difference between the axes objects before and after the PlotCone call, to isolate the objects created by PlotCone. Then we have to try to find a line object among that in order to have something to hang the legend on. If we are unable to find a line object, we return the first of the objects that we did find.
More Answers (0)
See Also
Categories
Find more on Convert Image Type 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!