Legend symbol in errorbar figure
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Stefano Alois
am 7 Apr. 2017
Beantwortet: JKM1000
am 23 Aug. 2018
I just downloaded the 2017a Matlab version. When I use the errorbar plot now in the legend it appears not only the symbol but the errorbar lines as well, which I don't like. I tried to look into the documentation, but there's no reference to how to disable the errorbar lines to show up in the legend. Do you know any workaround?
Thanks.
0 Kommentare
Akzeptierte Antwort
Randy Acheson
am 10 Apr. 2017
Starting in 2014b, the implementation of the 'legend' function was changed, and this is what is causing the new behavior. There is currently no supported way to remove the errorbars in the legend, and I have submitted an enhancement request to the developers of this function.
There is a workaround that will enable you to remove the errorbar lines. However, this is not recommended since this workaround will reduce the capabilities of your legend.
In order to roll back the change and get the legacy version of the 'legend' function, you can supply the 'legend' function with multiple outputs, and the errorbar lines will not appear. Here is an example:
x = 1:10:100;
y = [20 30 45 40 60 65 80 75 95 90];
err = 8*ones(size(y));
errorbar(x,y,err)
[lgd, icons, plots, txt] = legend('show');
You can refer to the documentation for the 'legend' function outputs here:
0 Kommentare
Weitere Antworten (2)
Dominic
am 30 Nov. 2017
I just stumbled across the same issue. A possible workaround is to plot dummy data outside the visible range with the same markers first. Then plot your data and apply the legend then only for the first elements.
For example:
% define markers
markers = {'x','o','^'};
% initialize figure for legend
for i = 1:3
plot(0,0,'Marker', markers{i},'LineStyle','none','Color','k'); hold on;
end
% plot the actual values with error bars
for i = 1:3
errorbar(xvals, yvaly, err, 'Marker', markers{i}, 'color', 'k');
end
% set visible range such that the dummy data is not visible
xlim([0, 10])
ylim([0.5, 1.5])
% add the legend to your liking
legend({'Version 1', 'Version 2', 'Version 3'}, 'location', 'northwest');
0 Kommentare
JKM1000
am 23 Aug. 2018
I agree that this is really ugly. I have been deleting the errorbar lines using a vector graphics editor, like inkscape. This is not ideal.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Errorbars finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!