How to edit colors for the line?

2 次查看(过去 30 天)
The legend line corlor is wrong. How do I change the black to green for the measured one?

采纳的回答

Walter Roberson
Walter Roberson 2020-8-5
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 个评论
Walter Roberson
Walter Roberson 2020-8-6
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.
Yingyi Huang
Yingyi Huang 2020-8-6
OMG, Thank you so much! Really appreciate your code! It is working now!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by