How to change Fontcolor xticks and yticks
7 views (last 30 days)
Show older comments
How can I change the color for xticks and ytick fonts?
figure('Name','Fig. 7 Change of plate thickness value* in the range from 0.5mm to 0.7mm for Abet Monocore 3D FP.')
plot(1,1)
plot(FP_plate_thickness(:,1),FP_plate_thickness(:,2),FP_plate_thickness(:,1),FP_plate_thickness(:,3),FP_plate_thickness(:,1),FP_plate_thickness(:,4),...
FP_plate_thickness(:,1),FP_plate_thickness(:,5),FP_plate_thickness(:,1),FP_plate_thickness(:,6),FP_plate_thickness(:,1),FP_plate_thickness(:,7),...
FP_plate_thickness(:,1),FP_plate_thickness(:,8), FP_plate_thickness(:,1),FP_plate_thickness(:,9),FP_plate_thickness(:,1),FP_plate_thickness(:,10),...
FP_plate_thickness(:,1),FP_plate_thickness(:,11),FP_plate_thickness(:,1),FP_plate_thickness(:,12),FP_plate_thickness(:,1),FP_plate_thickness(:,13),...
FP_plate_thickness(:,1),FP_plate_thickness(:,14), FP_plate_thickness(:,1),FP_plate_thickness(:,15),FP_plate_thickness(:,1),FP_plate_thickness(:,16),...
FP_plate_thickness(:,1),FP_plate_thickness(:,17),'LineWidth',1.5),
set (gcf,'position',[200,200,180,180]) % X pos, Y pos, X size, Y size
set (gca, 'FontSize',9,'FontName','Times New Roman') %Size font axis
grid on,
set(gca,'colororder',parula(16)) % to avoid color repetition in plotting lines
xtickformat('%gmm')
ytickformat('%g%%')
xticks(0.5:0.1:0.7)
yticks (-6:6:6)
ylim([-6 6])
title('FP_1','FontSize',10,'fontname','Times New Roman', 'Color', 'k')
0 Comments
Accepted Answer
Voss
on 29 Aug 2024
Assuming you just want to change the color of the x-tick and y-tick labels:
plot(1:10)
ax = gca();
ax.XAxis.TickLabelColor = 'r';
ax.YAxis.TickLabelColor = 'g';
Or if you want to change the color of each entire axis (including tick labels, tick marks, axis line, and grid lines):
plot(1:10)
ax = gca();
ax.XColor = 'r'; % or ax.XAxis.Color = 'r';
ax.YColor = 'g'; % or ax.YAxis.Color = 'g';
0 Comments
More Answers (2)
Image Analyst
on 29 Aug 2024
Here is a demo that shows you how to change just about everything on a plot:
% Demo to make a black graph with red Y axis, green X axis, and yellow grid. Markers are magenta with green lines between them.
% Initialization steps:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
% Create sample data.
X = 1 : 20;
Y = rand(1, 20);
% Plot green lines between the markers.
plot(X, Y, 'g-', 'LineWidth', 3);
hold on;
% Plot magenta markers.
plot(X, Y, 'ms', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
title('Y vs. X, Font Size 20, Blue', 'FontSize', 20, 'Color', 'b', 'FontWeight', 'bold');
% Make labels for the two axes.
xlabel('X Axis, Font Size 18, Green');
ylabel('Y axis, Font Size 24, Red');
yticks(0 : 0.2 : 1);
% Get handle to current axes.
ax = gca
% Now let's have fun changing all kinds of things!
% 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 = 18;
ax.YAxis.FontSize = 24;
% Make the axes tick marks and bounding box be really thick.
ax.LineWidth = 3;
% Let's have the tick marks go outside the graph instead of poking inwards
ax.TickDir = 'out';
% 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
% Now do stuff with the figure, as opposed to the axes control that is ON the figure.
% Maximize the figure
g = gcf; % Get handle to the current figure.
g.WindowState = 'maximized'; % Make it full screen.
g.Name = 'Demo by Image Analyst'; % Put a custom string into the titlebar.
g.NumberTitle = 'off'; % Don't have it put "Figure 1" before the name.
g.MenuBar = 'figure'; % or 'none'
g.ToolBar = 'figure'; % or 'none'
0 Comments
Subhajyoti
on 30 Aug 2024
You can retrieve the X and Y tick-labels from the plot and customize them, such as changing font-colour, using LaTex.
Here’s the code for a typical plot in MATLAB.
% Plot y = e^x for x = 1:10
x = 1:10;
y = exp(x);
plot(x, y,'LineWidth',1.5)
% set (gcf,'position',[200,200,180,180]) % X pos, Y pos, X size, Y size
set (gca, 'FontSize',9,'FontName','Times New Roman') %Size font axis
grid on,
set(gca,'colororder',parula(16)) % to avoid color repetition in plotting lines
xtickformat('%gmm')
ytickformat('%g%%')
Adding the following implementation customizes the font-color of the x-ticks to ‘green’:
% Get the current tick labels
ticklabels_x = get(gca,'XTickLabel');
% Prepend a color for each tick label
ticklabels_new_x = cell(size(ticklabels_x));
for i = 1:length(ticklabels_x)
ticklabels_new_x{i} = ['\color{green} ' ticklabels_x{i}];
end
% Set the tick labels
set(gca, 'XTickLabel', ticklabels_new_x);
I would recommend you go through the following documentation link to learn more about setting Tick label interpreter for ‘Axes Properties’ in MATLAB: https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html
0 Comments
See Also
Categories
Find more on Axis Labels 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!