Fontsize and properties of Xticklabels using figure handles
426 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Saugat Shrestha
el 19 de Mzo. de 2020
Comentada: mohabbat jafari
el 7 de En. de 2024
How do I cange the Xticklabels of a plot using figure handles?
0 comentarios
Respuesta aceptada
Adam Danz
el 19 de Mzo. de 2020
Editada: Adam Danz
el 19 de Mzo. de 2020
"How do I cange the Xticklabels of a plot using figure handles?"
Get the axis handle from the figure handle.
ax = gca(figureHandle);
Get the XAxis handle from the axis handle and set the FontSize of the x-axis only.
ax.XAxis.FontSize = 16;
or set the fontsize of the entire axis (x & y)
ax.FontSize = 14;
Set the XTick and XTick labels
ax.XTick = 1:4;
ax.XTickLabel = {'A' 'B' 'C' 'D'};
0 comentarios
Más respuestas (1)
Image Analyst
el 19 de Mzo. de 2020
Editada: Image Analyst
el 19 de Mzo. de 2020
There are xticklabels() and yticklabels() functions built-in. From the help:
xticklabels(labels) sets the x-axis tick labels for the current axes. Specify labels as a string array or a cell array of character vectors; for example, {'January','February','March'}. If you specify the labels, then the x-axis tick values and tick labels no longer update automatically based on changes to the axes.
Also, see my little demo that shows you how to change a bunch of things independently:
% Create sample data.
X = 1 : 20;
Y = rand(1, 20);
plot(X, Y, 'gs-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
title('Y vs. X', 'FontSize', 12);
% Make labels for the two axes.
xlabel('X Axis');
ylabel('Y axis');
% Get handle to current axes.
ax = gca
% This sets background color to black.
ax.Color = 'k'
ax.YColor = 'r';
% Make the x axis dark green.
darkGreen = [0, 0.6, 0];
ax.XColor = darkGreen;
% Make the grid color yellow.
ax.GridColor = 'y';
ax.GridAlpha = 0.9; % Set's transparency of the grid.
% Set x and y font sizes.
ax.XAxis.FontSize = 15;
ax.YAxis.FontSize = 24;
% The below would set everything: title, x axis, y axis, and tick mark label font sizes.
% ax.FontSize = 34;
% Bold all labels.
ax.FontWeight = 'bold';
hold off
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278150/image.png)
3 comentarios
Image Analyst
el 11 de Dic. de 2022
You could turn the text labels off and then make your own tick labels with the text() function and place it wherever you want.
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!