Plotting curves over histogram: problem with legend

Hello lovely people,
I am adding two curves to my histogram. It all looks well and good, but there's a problem with the legend.
As you can see in the attachent, the legend does appear, with the desired lables. The histogram indicator is there, but the line plot indicators are missing.
I'm sure I'm doing something wrong, but cannot figure out what. Please could someone help?
Many thanks in advance!
Lukas
EDIT: I exported the figure as .svg and they magically appeared! Maybe it's just a bug then?
hold on
hist = histogram(V, [0.5:28.5],'normalization','probability','FaceColor',[0.3010 0.7450 0.9330],'DisplayName','measured data')
plot1 = plot(Weib_Bow(:,1),Weib_Bow(:,2),'DisplayName','Bowden')
plot2 = plot(Weib_Mat(:,1),Weib_Mat(:,2),'DisplayName','MATLAB')
legend
title('wind speed frequency distribution')
xlabel('V (m/s)')
ylabel('probability')
hold off

 Accepted Answer

If exporting shows the data, yet viewing on your screen does not, I wonder if this is an issue with you graphics? The code itself works on my computer, so it's something about how your system is displaying. Here's a quick approximation.
r = wblrnd(4,2,1,1000);
h=histogram(r,10,'DisplayName','measured data');
[N,~,X]=histcounts(r,10);
hold on
plot1 = plot(unique(X),N,'-k','DisplayName','Bowden');
plot2 = plot(unique(X)*1.01,N,'-c','DisplayName','MATLAB');
hold off
legend
Try seeing if you can update your graphics driver. See this post.

1 Comment

Many thanks! I think it is my graphics...
Didn't update the driver but restarted my computer since and it appears to be working again.
Thanks for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!