Errorbar: change line width of marker line, not of error bars

66 ビュー (過去 30 日間)
katha_lala
katha_lala 2018 年 5 月 7 日
回答済み: Zhuohe Liu 2023 年 4 月 14 日
Hello everyone,
I plotted multiple lines with their errorbars using the following function:
errorbar(angle,mw,stdev);
However, with some lines and errorbars in one plot, this gets a bit messy. What I wanted to do, is to highlight the "main marker line" (the "mw" values so to say) to make them stand out a bit more. But if I do it via "LineWidth", the main line plus errorbar becomes bigger. Is there a way to exlude the errorbars?
Thank you in advance!

採用された回答

sloppydisk
sloppydisk 2018 年 5 月 7 日
編集済み: sloppydisk 2018 年 5 月 7 日
Unfortunately the errorbar data type does not have any children you can edit directly. I would probably do something like this as a workaround:
angle = rand(20, 1);
mw = 1:20;
stdev = .1*ones(20, 1);
errorbar(mw, angle,stdev, 'LineStyle', 'None');
hold on
plot(mw, angle, 'LineWidth', 3);
hold off
  2 件のコメント
katha_lala
katha_lala 2018 年 5 月 7 日
Thank you! That's what I did as a workaround, but good to know that there is no better alternative to that :)
Loc Q. Huynh
Loc Q. Huynh 2022 年 6 月 25 日
What if I want to add the legend after that? In my case, I have 2 arrays and the legend showed 4 set of data instead of 1.

サインインしてコメントする。

その他の回答 (1 件)

Zhuohe Liu
Zhuohe Liu 2023 年 4 月 14 日
Actually, you may control separately the cap, bar and line style using hidden properties. For example, as I tested in r2023a. However, the legend icon might need to be changed separately.
figure
e = errorbar([1, 2], [1, 2], [0.5, 0.6], 'DisplayName', 'Demo');
e.Cap.LineWidth = 1;
e.Bar.LineWidth = 1;
e.Line.LineWidth = 2;
xlim([0, 3]);
legend('show')

カテゴリ

Help Center および File ExchangeErrorbars についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by