11.1 C
London
Sunday, July 7, 2024
HomeStatistics TutorialStatologyHow to Hide Axes in Matplotlib (With Examples)

How to Hide Axes in Matplotlib (With Examples)

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...

You can use the following syntax to hide axes in Matplotlib plots:

import matplotlib.pyplot as plt

#get current axes
ax = plt.gca()

#hide x-axis
ax.get_xaxis().set_visible(False)

#hide y-axis 
ax.get_yaxis().set_visible(False)

The following examples show how to use this syntax in practice.

Example 1: Hide X-Axis

The following code shows how to create a scatterplot and hide the x-axis:

import matplotlib.pyplot as plt

#define data
x = [3, 4, 4, 6, 7, 8, 8, 12]
y = [11, 12, 12, 14, 17, 15, 14, 19]

#create scatterplot
plt.scatter(x, y)

#get current axes
ax = plt.gca()

#hide x-axis
ax.get_xaxis().set_visible(False)

Hide x-axis in Matplotlib

Example 2: Hide Y-Axis

The following code shows how to create a scatterplot and hide the y-axis:

import matplotlib.pyplot as plt

#define data
x = [3, 4, 4, 6, 7, 8, 8, 12]
y = [11, 12, 12, 14, 17, 15, 14, 19]

#create scatterplot
plt.scatter(x, y)

#get current axes
ax = plt.gca()

#hide y-axis
ax.get_yaxis().set_visible(False)

Example 3: Hide Both Axes

The following code shows how to create a scatterplot and hide both axes:

import matplotlib.pyplot as plt

#define data
x = [3, 4, 4, 6, 7, 8, 8, 12]
y = [11, 12, 12, 14, 17, 15, 14, 19]

#create scatterplot
plt.scatter(x, y)

#get current axes
ax = plt.gca()

#hide x-axis
ax.get_xaxis().set_visible(False)

#hide y-axis
ax.get_yaxis().set_visible(False)

Example 4: Remove Axes & Borders Completely

The following code shows how to remove the axes and the plot borders completely:

import matplotlib.pyplot as plt

#define data
x = [3, 4, 4, 6, 7, 8, 8, 12]
y = [11, 12, 12, 14, 17, 15, 14, 19]

#create scatterplot
plt.scatter(x, y)

#get current axes
ax = plt.gca()

#hide axes and borders
plt.axis('off')

Additional Resources

How to Change the Number of Ticks in Matplotlib
How to Rotate Tick Labels in Matplotlib
How to Set Axis Ranges in Matplotlib

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