How to locate the plotting title above the legend, where the legend is placed "northoutside"?
63 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Israa Ahmed
am 13 Sep. 2021
Kommentiert: Israa Ahmed
am 14 Sep. 2021
If the legend is placed "northoutside" (i.e. at the top outside of my plot), how to put the title above that legend?
0 Kommentare
Akzeptierte Antwort
Dave B
am 14 Sep. 2021
Bearbeitet: Dave B
am 14 Sep. 2021
You can put a title on the legend, but I think you just want a master title for everything. You can do that by placing your axes in a tiledlayout. Tiledlayout is intended for multiple axes, but it happens to also have a title which works out well as it is placed above the legend. (relevant bits at the beginning and end:
tcl=tiledlayout(1,1);
nexttile
%% This section is just making a random fun plot
t=readtable(fullfile(matlabroot,'examples','matlab','data','BicycleCounts.csv'));
scatter(-t.Westbound,t.Timestamp.Month,20,'filled','YJitter','density','MarkerFaceAlpha',.5)
hold on
scatter(t.Eastbound,t.Timestamp.Month,20,'filled','YJitter','density','MarkerFaceAlpha',.5)
xlim([-1 1]*max(abs(xlim)))
xlabel('Number of Bicycles')
ylabel('Month')
yticks(1:12)
ylim('tight')
xticklabels(abs(xticks))
h=legend('Westbound','Eastbound','Location','northoutside','Orientation','horizontal');
title(h,'Direction'); % Just to see what a legend title looks like
title(tcl,'Bicycle Traffic')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend 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!