📜  Python中的 Matplotlib.axes.Axes.yaxis_inverted()

📅  最后修改于: 2022-05-13 01:54:26.889000             🧑  作者: Mango

Python中的 Matplotlib.axes.Axes.yaxis_inverted()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。

matplotlib.axes.Axes.yaxis_inverted()函数

matplotlib 库的 axes 模块中的Axes.yaxis_inverted()函数返回 y 轴是否反转。

下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.yaxis_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_yaxis()
  
ax.set_title('matplotlib.axes.Axes.yaxis_inverted() \
Example\n',
             fontsize = 14, fontweight ='bold')
x = ax.yaxis_inverted()
ans ="No"
if x:
    ans ="Yes"
ax.text(1.8, -0.02, "Y-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_yaxis()  
ax.set_xlabel('Performance')
x = ax.yaxis_inverted()
ans ="No"
if x:
    ans ="Yes"
      
ax.set_title('matplotlib.axes.Axes.yaxis_inverted() \
Example\n',
             fontsize = 14, fontweight ='bold')
ax.text(3, -0.75, "Y-axis is inverted ? : " + ans, 
        style ='italic', fontsize = 12)
  
plt.show()

输出: