📜  Python中的 Matplotlib.pyplot.ylabels()

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

Python中的 Matplotlib.pyplot.ylabels()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 PyplotMatplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。

matplotlib.pyplot.ylabel()函数

matplotlib 库的 pyplot 模块中的ylabel()函数用于设置 x 轴的标签。

下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.ylabel()函数:

示例 #1:

# Implementation of matplotlib.pyplot.ylabels() 
# function
    
import numpy as np
import matplotlib.pyplot as plt
   
t = np.arange(-180.0, 180.0, 0.1)
s = np.radians(t)/2.
   
plt.plot(t, s, '-', lw = 2)
   
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('ylabels() function')
plt.grid(True)
   
plt.show()

输出:

示例 #2:

# Implementation of matplotlib.pyplot.ylabels() 
# function
   
import numpy as np
import matplotlib.pyplot as plt
  
valx1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
  
valy1 = np.cos(2 * np.pi * valx1) * np.exp(-valx1)
y2 = np.cos(2 * np.pi * x2)
  
plt.subplot(2, 1, 1)
plt.plot(valx1, valy1, 'o-')
plt.title('ylabel() Example')
plt.ylabel('Damped oscillation')
  
plt.subplot(2, 1, 2)
plt.plot(x2, y2, '.-')
plt.xlabel('time (s)')
plt.ylabel('Undamped')
  
plt.show()

输出: