Changing Errorbar Markersize within Legend
13 ビュー (過去 30 日間)
古いコメントを表示
Hey,
following problem:
I am plotting some errorbars in my figure. I control the appearend size of the y value with 'Markersize'. In a normal plot, changing the markersize also changes the markersize within the legend. Also changing the Linewith will change the Linewith in the plot and also in the legend.
This is only partly true for errorbars. Changing the Linewith in errorbars will change the thickness of the errobar in the plot and the legends, but markersize will only affect the markersize in the plot but not in the legend! So for a errorbar like
e=errorbar(x,y,L,U,'kx','Linewidth',3)
e.MarkerSize = 10;
the errorbar looks fine in the plot, but in the legend the Marker within the bar is nearly invisible compared to the plot. So how can I cange that??
Additionally, I plot too much and the legend would be overfull, so I reduce it and just explain the generell meaning in the legend.
Therefore I do something like
plot(NaN,NaN,'b-')
plot(NaN,NaN,'r-')
errorbar(NaN,NaN,NaN,NaN,'kx')
and use this inivisbel plots so setup the legend.
Unfortunaltely, the plots do exactly what I want. Even so they plot nothing because of the NaN, in the legend they appear as blue and red lines. The errorbar in the legend instead simply shows a black X, but the errorbar itsself in the legend is missing. The only why to plot the errorbar in the legend is to not use NaN values for x,y,L and U. Only using NaN for x and y makes the errorbar appear in the legend but without the Cap marking. So I have to bypass this by plotting an errorbar with finit values outside the x and y range I want to look at like:
errorbar(1,400,1,1,'kx')
ylim([0 300])
only to get a placeholder errobar for my legend, that still has the small Markersize mentioned above.
So how to compete with that. My way seems way too complicated fpr this problem.
0 件のコメント
採用された回答
Srija Kethiri
2022 年 2 月 14 日
Hi Marc,
It is only possible in Errorbar's getLegendGraphic to allow marker size up to 18 if the marker style is 'point'.
If you want to increase the marker size above 18 then you can use the following workaround.
[lh,icons] = legend('Data', 'Location', 'southeast');
% search for the correct icon in the icons array. errorbar icons are created as
% Group objects (AKA hggroups) and their Tag property is set to match their corresponding
% text label (in this case, “Data”)
ourIcon = findobj(icons, “Tag”, “Data”, “Type”, “hggroup”);
% display the horizontal lines
% the horizontal lines of the errorbar are present in the icon, but for some reason it has not
% LineStyle value, and is thus invisible
whiskerLine = whiskerLine = ourIcon.Children(1).Children(2);
whiskerLine.LineStyle = '-';
% add the vertical ticks
whiskerTickY1 = whiskerLine.YData(1) - (whiskerLine.XData(2) - whiskerLine.XData(1)) / 2;
whiskerTickY2 = whiskerLine.YData(1) + (whiskerLine.XData(2) - whiskerLine.XData(1)) / 2;
% make sure these are children of ourIcon
whiskerLeftTick = plot(ourIcon, [whiskerLine.XData(1) whiskerLine.XData(1)], [whiskerTickY1 whiskerTickY2],...
“LineStyle”, whiskerLine.LineStyle, “Color”, whiskerLine.Color);
whiskerRightTick = plot(ourIcon, [whiskerLine.XData(2) whiskerLine.XData(2)], [whiskerTickY1 whiskerTickY2],...
“LineStyle”, whiskerLine.LineStyle, “Color”, whiskerLine.Color);
Hope this helps.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Errorbars についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!