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

 채택된 답변

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

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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by