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

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 2 月 13 日

0 投票

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 件のコメント

Lukas Price-Nowak
Lukas Price-Nowak 2021 年 2 月 13 日
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 Exchange2-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