Plot: vertical legend for x axis

I have the horizontal legend for x-axis as you see in the attached graphics. But in this way numbers are hard to see. I would like to set the legend to be vertical to improve readability. Please advise.

 Risposta accettata

Star Strider
Star Strider il 5 Apr 2018

0 voti

See if you can use the 'XTickLabelRotation' (link) ‘axes’ property. (I do not remember when this option first appeared. I believe it was R2015b.)

4 Commenti

Would you explain how it works in the following example?
w=0:0.05:1;
ncount1 = histc(x(:,1),w);
relativefreq1=ncount1/NSamples;
ncount2 = histc(x(:,2),w);
relativefreq2=ncount2/NSamples;
ncount3 = histc(x(:,3),w);
relativefreq3=ncount3/NSamples;
figure (4)
plot(w, relativefreq1)
hold on
plot(w, relativefreq2,'LineWidth',1.0)
hold on
plot(w, relativefreq3,'LineWidth',1.5)
legend('Data1','Data2','Data')
title('Distribution of Data')
xlabel('Data')
ylabel('Frequency')
xlim([min(w) max(w)])
set(gca, 'xtick', w)
Tweak the last line to be:
set(gca, 'xtick', w, 'XTickLabelRotation',90)
Thank you.
As always, my pleasure.

Accedi per commentare.

Più risposte (0)

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by