Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。
matplotlib.axes.Axes.axis()函數
matplotlib庫的axiss模塊中的Axes.axis()函數是獲取或設置某些軸屬性的便捷方法。
用法: Axes.axis(self, *args, **kwargs)
參數:此方法接受以下描述的參數:
- xmin,xmax,ymin,ymax:這些參數是要設置的軸限製。
axis([xmin, xmax, ymin, ymax])
- option:此參數用於打開或關閉軸線和標簽或選項。
- emit:此參數用於檢查是否已將軸極限更改通知觀察者。
返回值:此方法返回以下內容:
- xmin,xmax,ymin,ymax:這將返回軸限製。
以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.axis()函數:
範例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()
輸出:
範例2:
# 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()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.axis() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。