Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Matplotlib.axes.Axes.axis() in Python

  • Last Updated : 19 Apr, 2020

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.axis() Function

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

The Axes.axis() function in axes module of matplotlib library is the convenience method to get or set some axis properties.

Syntax: Axes.axis(self, *args, **kwargs)

Parameters: This method accept the following parameters that are described below:

  • xmin, xmax, ymin, ymax : These parameter are the axis limits to be set.
    axis([xmin, xmax, ymin, ymax])
  • option : This parameter is the used to turns axis lines and labels on or off or the options.
  • emit : This parameter is used to check whether the observers are notified of the axis limit change.

Returns:This method returns the following:

  • xmin, xmax, ymin, ymax :This returns the axis limits.

Below examples illustrate the matplotlib.axes.Axes.axis() function in matplotlib.axes:

Example 1:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
labels = 'Geek1', 'Geek2', 'Geek3', 'Geek4', 'Geek5'
sizes = [95, 230, 145, 40, 65]
explode = (0, 0.2, 0, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode = explode, labels = labels,
        autopct ='% 1.0f %%',
        shadow = True, startangle = 90)
ax1.set_title('matplotlib.axes.Axes.axis() \
Example\n', fontsize = 14, fontweight ='bold')


Example 2:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.cbook as cbook
# image used is 
# / uploads / 20200402214740 / geek.jpg
with cbook.get_sample_data('geek.JPG') as image_file:
    image = plt.imread(image_file)
fig, (ax, ax1) = plt.subplots(2, 1)
im = ax.imshow(image)
patch = patches.Rectangle((0, 0), 260, 200
                          transform = ax.transData)
ax.set_title('Without Axis Function',
             fontsize = 10, fontweight ='bold')
im = ax1.imshow(image)
patch = patches.Rectangle((0, 0), 260, 200,
                          transform = ax1.transData)
ax1.set_title("Axis Function with 'Off' option",
              fontsize = 10, fontweight ='bold')


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!