Matplotlib.axes.Axes.axis() in Python (original) (raw)

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

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:

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

Python3 `

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:

Python3 `

Implementation of matplotlib function

import matplotlib.pyplot as plt import matplotlib.patches as patches import matplotlib.cbook as cbook

image used is

https://media.geeksforgeeks.org / wp-content

/ 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: