Skip to content
Related Articles

Related Articles

Matplotlib.axes.Axes.axis() in Python

Improve Article
Save Article
  • Last Updated : 19 Apr, 2020
Improve Article
Save Article

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

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.axis('square')
ax1.set_title('matplotlib.axes.Axes.axis() \
Example\n', fontsize = 14, fontweight ='bold')
plt.show()

Output:

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)
im.set_clip_path(patch)
ax.set_title('Without Axis Function',
             fontsize = 10, fontweight ='bold')
  
im = ax1.imshow(image)
patch = patches.Rectangle((0, 0), 260, 200,
                          transform = ax1.transData)
im.set_clip_path(patch)
ax1.axis('off')
  
ax1.set_title("Axis Function with 'Off' option",
              fontsize = 10, fontweight ='bold')
plt.show()

Output:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!