How to Italicize either of the axis tick labels ?

157 views (last 30 days)
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.

Accepted Answer

VBBV
VBBV on 16 May 2023
Edited: VBBV on 16 May 2023
Use '\it label text'
% italic font
xticklabels({'\it text1','\it text2'})
% normal (plain) font
xticklabels({'text1','text2'})
  2 Comments
Arup Dutta
Arup Dutta on 16 May 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 on 16 May 2023
Edited: VBBV on 16 May 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

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 16 May 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.

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!