askvity

# How to Make Axis Numbers Bold in MATLAB

Published in MATLAB Plotting 4 mins read

To make the axis numbers (tick labels) bold in MATLAB, you modify the FontWeight property of the axis objects.

How to Make Axis Numbers Bold in MATLAB

Making axis numbers bold in MATLAB enhances the readability of your plots, making the tick values stand out more prominently. The standard way to achieve this is by accessing and modifying the properties of the axis object associated with your plot.

Method 1: Using Axis Object Properties (Recommended)

The most flexible and recommended method involves getting a handle to the current axes object and setting the FontWeight property for its XAxis and YAxis components.

Steps:

  1. Create or Select a Plot: First, ensure you have a plot window open or create a new plot.
  2. Get Current Axis Handle: Use the gca function to get the handle to the current axes object.
  3. Modify Font Weight: Access the XAxis and YAxis properties of the axis object and set their FontWeight property to 'bold'.

Example Code:

% Create a sample plot
figure; % Create a new figure window
plot(1:10, (1:10).^2); % Plot some data
title('Sample Plot with Bold Axis Numbers');
xlabel('X Values');
ylabel('Y Values');

% Get the current axes object
ax = gca;

% Make the X-axis numbers (tick labels) bold
ax.XAxis.FontWeight = 'bold';

% Make the Y-axis numbers (tick labels) bold
ax.YAxis.FontWeight = 'bold';

% Optional: You can also adjust FontSize here if needed
% ax.XAxis.FontSize = 10;
% ax.YAxis.FontSize = 10;

After running this code, the numbers along both the X and Y axes will appear in bold text.

Understanding FontWeight and Axis Objects

The concept of using 'FontWeight', 'bold' to control text thickness is common in MATLAB plotting, as seen in the reference provided:

xlabel('X Axis', 'FontSize', 9, 'FontWeight', 'bold');

This specific line from the reference makes the text label "X Axis" bold. While the reference doesn't explicitly show how to make the numbers bold, it introduces the FontWeight property and hints at interacting with axis components (ax. XAxis.).

To make the axis numbers bold, you apply the same FontWeight property, but you apply it to the XAxis and YAxis properties of the graphics axis object (ax), which control the appearance of the tick marks and labels.

Method 2: Using the set function on the Axes (Less Specific)

An older or less specific method is to set the FontWeight property directly on the axes handle using the set function. This applies the font weight setting more broadly to the entire axis object, which typically includes tick labels, axis labels, and the title.

% Create a sample plot
figure;
plot(1:10, sin(1:10));
title('Plot with Bold Axis Font');
xlabel('X-axis Label');
ylabel('Y-axis Label');

% Get the current axes object
ax = gca;

% Make the entire axis font bold (including numbers, labels, title)
set(ax, 'FontWeight', 'bold');

While this makes the numbers bold, it also makes the axis labels and title bold, which might not be the desired effect if you only want the numbers bold.

Comparison of Methods

Here's a quick comparison of the two primary approaches:

Feature Method 1: Axis Object Properties (ax.XAxis.FontWeight) Method 2: set on Axes (set(ax, 'FontWeight'))
What becomes bold? Only the axis numbers (tick labels) Tick labels, axis labels, title
Specificity High (control X and Y axes separately) Lower (applies broadly to the axes)
Control Granular control over individual axis properties Simpler syntax for applying properties broadly
Recommended? Yes, for precise control Use if making everything bold is acceptable

In most cases, using Method 1 with the axis object properties (ax.XAxis.FontWeight = 'bold';) is preferred for making only the axis numbers bold while leaving the labels and title with their default font weight (unless you explicitly set them otherwise).

Related Articles