14.7 C
London
Tuesday, July 2, 2024
HomePythonMatplotlib in PythonHow to Remove Ticks from Matplotlib Plots

How to Remove Ticks from Matplotlib Plots

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

Often you may want to remove ticks from one or more axes in a Matplotlib plot. Fortunately this is easy to do using the tick_params() function.

This tutorial shows several examples of how to use this function in practice based on the following scatterplot:

import matplotlib.pyplot as plt

#create data
x = [25, 12, 15, 14, 19, 23, 25, 29]
y = [5, 7, 7, 9, 12, 9, 9, 4]

#create scatterplot
plt.scatter(x, y, s=200)

Example 1: Remove Ticks From a Single Axis

The following code shows how to remove the ticks from the y-axis:

plt.tick_params(left=False)

plt.scatter(x, y, s=200)

Matplotlib remove ticks from y-axis

And the following code shows how to remove the ticks from the x-axis:

plt.tick_params(bottom=False)

plt.scatter(x, y, s=200)

Matplotlib remove ticks from x-axis

Example 2: Remove Ticks from Both Axes

The following code shows how to remove the ticks from both axes:

plt.tick_params(left=False,
                bottom=False)

plt.scatter(x, y, s=200)

Matplotlib remove ticks from both axes

Example 3: Remove Ticks and Labels from Axes

The following code shows how to remove the ticks and the labels from both axes:

plt.tick_params(left=False,
                bottom=False,
                labelleft=False,
                labelbottom=False)

plt.scatter(x, y, s=200)

Remove ticks and labels from Matplotlib plot

You can find more Matplotlib tutorials here.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories