How to make errorbar transparent?

164 ビュー (過去 30 日間)
supernoob
supernoob 2019 年 7 月 24 日
編集済み: David Saidman 2021 年 4 月 22 日
How can I make a plot with discrete errorbar points which are transparent?
  4 件のコメント
Adam Danz
Adam Danz 2019 年 7 月 25 日
編集済み: Adam Danz 2019 年 7 月 25 日
Here's an alternative that will take a little work. You could create a function that has the same inputs as errorbar(). In that function you can create vertical lines that span from the lower to upper error limits for each point. That you're dealing with line objects and you'll be able to control their alpha values by adding an alpha value to the 4th position of the RGB color value.
h = plot();
h.Color = [h.Color, 0.5]; % for 50% transparency
Gino Delfe
Gino Delfe 2020 年 9 月 3 日
it works for plot, but not when you use it on the function errorbar()

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

採用された回答

Adam Danz
Adam Danz 2020 年 9 月 3 日
編集済み: Adam Danz 2020 年 9 月 3 日
Unlike many line plots, the color property cannot be used to set transparency in errorbar().
Transparency can be set from within the hidden Bar and Line objects that represent the errorbars and trend line, respectively.
% Plot errorbars
cla
hold on
plot(rand(20),rand(20)*2-.5, 'yo', 'MarkerFaceColor', 'k', 'MarkerSize', 15, 'LineWidth', 1.5);
h = errorbar(linspace(0,1,5), linspace(0,1,5), .5*ones(1,5), 'r', 'LineWidth', 10);
% Set transparency level (0:1)
alpha = 0.65;
% Set transparency (undocumented)
set([h.Bar, h.Line], 'ColorType', 'truecoloralpha', 'ColorData', [h.Line.ColorData(1:3); 255*alpha])
  2 件のコメント
David Saidman
David Saidman 2021 年 4 月 21 日
編集済み: David Saidman 2021 年 4 月 22 日
This worked.
The end caps on the errorbar were still solid, but I was able to make them transparent with other undocumented properties in the errorbar object. In case someone else may be trying to do the same thing:
The hidden properties h.CapH and h.MarkerHandle can be adjusted the same way as h.Line and h.Bar as above, but use FaceColorData & FaceColorType and EdgeColorData & EdgeColorType properties in place of ColorData & ColorType (or can be set to 'visible','off').
Adam Danz
Adam Danz 2021 年 4 月 21 日
編集済み: Adam Danz 2021 年 4 月 21 日
Thanks for the addition, @David Saidman.
Unless there's something I'm missing, the FaceColor does not need changed for the caps. The transparency can be set in the EdgeColorData and EdgeColorType of the Cap handle.
set(h.Cap, 'EdgeColorType', 'truecoloralpha', 'EdgeColorData', [h.Cap.EdgeColorData(1:3); 255*alpha])

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by