當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.axes.Axes.xaxis_inverted()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。

matplotlib.axes.Axes.xaxis_inverted()函數

matplotlib庫的axiss模塊中的Axes.xaxis_inverted()函數返回x軸是否反轉。

用法: Axes.xaxis_inverted(self)


參數:此方法不接受任何參數。

返回:此方法返回x軸是否反轉。

以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.xaxis_inverted()函數:

範例1:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
import numpy as np 
   
fig, ax = plt.subplots() 
   
ax.axvspan(1.5, 2.5, facecolor ='g', alpha = 0.7) 
ax.invert_xaxis() 
  
ax.set_title('matplotlib.axes.Axes.xaxis_inverted()\ 
 Example\n', 
             fontsize = 14, fontweight ='bold') 
x = ax.xaxis_inverted() 
ans ="No"
if x:
    ans ="Yes"
ax.text(2.2, 1.02, "X-axis is inverted ?:" + ans, 
        style ='italic', fontsize = 12) 
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
import numpy as np 
   
np.random.seed(19680801) 
plt.rcdefaults() 
fig, ax = plt.subplots() 
  
people = ('Geek1', 'Geek2', 'Geek3', 
          'Geek4', 'Geek5') 
y_pos = np.arange(len(people)) 
performance = 3 + 4.5 * np.random.rand(len(people))**2
error = np.random.rand(len(people)) 
  
ax.barh(y_pos, performance, xerr = error,  
        align ='center', color ="green") 
ax.set_yticks(y_pos) 
ax.set_yticklabels(people) 
  
ax.invert_xaxis()   
ax.set_xlabel('Performance') 
x = ax.xaxis_inverted() 
ans ="No"
if x:
    ans ="Yes"
      
ax.set_title('matplotlib.axes.Axes.xaxis_inverted()\ 
Example\n', 
             fontsize = 14, fontweight ='bold') 
ax.text(6, 4.75, "X-axis is inverted ?:" + ans,  
        style ='italic', fontsize = 12) 
  
plt.show()

輸出:




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.xaxis_inverted() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。