When you specify errorbar linestyles, how do you port them into the legend?

1 次查看(过去 30 天)
I found a great explanation of how to force a LineStyle change in the errorbars of an errorbar plot, but I've hit a corollary snag in my R2019a environment: when I call legend in my plot using that workaround, the colours and errorbar shapes are ported - but the linestyles I've used the link technique to edit in are not. How can I make the legend reflect my modified errorbars?
h1 = errorbar(1,1,0.3,0.2,'or');
xlim([0 5])
ylim([0 3])
h1.Bar.LineStyle = 'dashdot'
hold on
h2 = errorbar(3,1.4,0.1,0.4,'ok');
h2.Bar.LineStyle = 'dotted'
hold off
hl = legend('VarName1','VarName2');
legend boxoff
title(hl,'LegendTitle')
Note that the figure the code above generates shows different linestyles for the confidence intervals, but that these are not reflected in the legend, which shows solid lines where 'dashdot' or 'dotted' should be used.
I will also note that I can hack in appropriate lines and markers (albeit horiztonal instead of vertical, like the errorbar tokens) by the usual workaround of hold on; plot(desired style but outside desired window) ... ; actual errorbar calls ; hold off. But doing it this way loses the errorbar tokens, which I wanted to keep (assuming the linestyles showed well enough in the vertical space allotted).
  6 个评论
Daniel
Daniel 2020-10-19
No problem, Adam. I figure it's far better to be open about the likelihood of a solution here than to leave it otherwise abandoned. That gets my goat when I see it on other questions...
To the community at large: feel free to link to this query if you need an example of an OP proactively responding and keeping the community informed (and incidentally, providing background info + link and a MWE in the post) for someone else.

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by