How to Italicize either of the axis tick labels ?

157 visualizzazioni (ultimi 30 giorni)
I need to italicize either xtick labels or ytick labels. I am using FontAngle command but it is changing both of them to italic. I need to change only one of the axes tick labels to italic. Suppose if I need to make the ytick label italic the xtick label should remain plain, but the the use of 'FontAngle' command changing the whole texts of the plots to italic. can anyone help me in this regard.

Risposta accettata

VBBV
VBBV il 16 Mag 2023
Modificato: VBBV il 16 Mag 2023
Use '\it label text'
% italic font
xticklabels({'\it text1','\it text2'})
% normal (plain) font
xticklabels({'text1','text2'})
  2 Commenti
Arup Dutta
Arup Dutta il 16 Mag 2023
Thank you for the help. But if I need to mark the labels with a data set of text (from a column of excel), how can I use them in this format?
VBBV
VBBV il 16 Mag 2023
Modificato: VBBV il 16 Mag 2023
% italic font
xticklabels({[repmat('\it',1,length(dataset)), sprintf('%s',dataset)]})
After importing the dataset of text from excel to a variable say dataset use sprintf function as shown above

Accedi per commentare.

Più risposte (1)

Steven Lord
Steven Lord il 16 Mag 2023
h = plot(1:10, 1:10);
xlabel('abracadabra')
ylabel('hocus pocus')
ax = ancestor(h, 'axes');
The XAxis and YAxis properties of the axes allow you to adjust properties of the X and Y axes independently. Let's make the X axis text italicized and the Y axis text in a larger font.
xaxisobj = ax.XAxis;
xaxisobj.FontAngle = 'italic';
yaxisobj = ax.YAxis;
yaxisobj.FontSize = 20;
See the description of the XAxis, YAxis, and ZAxis properties in the Rulers section of the documentation page for axes properties for more information.

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by