correct and custom legend
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello everyone, I would like to ask the community a couple of questions:
First: in order to have nicer labels in the legend, i created the following time series from available data
germany = GDPdeuYear
france = GDPdeuYear + GDPfraYear
italy = GDPdeuYear + GDPfraYear + GDPitaYear
spain = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear
austria = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear
belgium = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear
finland = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear + GDPfinYear
ireland = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear + GDPfinYear + GDPirlYear
luxemburg = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear + GDPfinYear + GDPirlYear + GDPluxYear
netherlands = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear + GDPfinYear + GDPirlYear + GDPluxYear + GDPnldYear
portugal = GDPdeuYear + GDPfraYear + GDPitaYear + GDPespYear + GDPautYear + GDPbelYear + GDPfinYear + GDPirlYear + GDPluxYear + GDPnldYear + GDPprtYear
I want to plot them:
figure(),
plot(calDateYear,portugal)
H=area(calDateYear,portugal);
set(H(1),'FaceColor',[0.2 0 0]);
hold on
plot(calDateYear,netherlands)
H=area(calDateYear,netherlands);
set(H(1),'FaceColor',[0.35 0 0]);
hold on
plot(calDateYear,luxemburg)
H=area(calDateYear,luxemburg);
set(H(1),'FaceColor',[0.5 0  0]);
hold on
plot(calDateYear,ireland)
H=area(calDateYear,ireland);
set(H(1),'FaceColor',[0.65 0  0]);
hold on
plot(calDateYear,finland)
H=area(calDateYear,finland);
set(H(1),'FaceColor',[0.85 0  0]);
hold on
plot(calDateYear,belgium)
H=area(calDateYear,belgium);
set(H(1),'FaceColor',[1 0  0]);
hold on
plot(calDateYear,austria)
H=area(calDateYear,austria);
set(H(1),'FaceColor',[1 0.2  0.2]);
hold on
plot(calDateYear,spain)
H=area(calDateYear,spain);
set(H(1),'FaceColor',[1 0.4  0.4]);
hold on
plot(calDateYear,italy)
H=area(calDateYear,italy);
set(H(1),'FaceColor',[1 0.6  0.6]);
hold on
plot(calDateYear,france)
H=area(calDateYear,france);
set(H(1),'FaceColor',[1 0.8  0.8]);
hold on
plot(calDateYear,germany)
H=area(calDateYear,germany);
set(H(1),'FaceColor',[1 0.9  0.9]);
hold off
ylabel('GDP');
xlabel('Year');
xticklabels([1996:1:2017]);
xticks(calDateYear(1:22)); 
axis([calDateYear(1) calDateYear(end) 0 max(portugal)]);
title('GDP per year per country (in Dollar)');
legend({'portugal','netherlands','luxemburg','ireland','finland','belgium','austria','spain','italy','france','germany'},'Location','northwest');
The problem is that the legend looks like this:

Instead, i would like every color to represent the country. That is, i would have 11 squares in the legend (not 6 squares and 5 lines). In the graph, Germany is represented by the lightest-red color, but in the legend it is shown as a darker color.
Could anyone help?
0 件のコメント
回答 (1 件)
  Image Analyst
      
      
 2018 年 12 月 4 日
        
      編集済み: Image Analyst
      
      
 2018 年 12 月 4 日
  
      Unless you want to really dive into the details of the legend children, I think you should plot everything as a line or an area.  I think a line would be better.  What if a country plotted later had higher values - would it cover up the one plotted earlier with area?  I think maybe.
Personally I hate charts like that and find them very confusing, and I think others might agree.  One might reasonably think that Portugal had the highest GDP since it's values are on top and map to the highest values on the Y axis, not Germany.  However it looks like the way you constructed it, each country is just the difference from the curve below it.  And since the baseline is not flat because of that, it's hard to get a good idea of what the contribution really is.
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Legend についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

