📜  Python中的 Matplotlib.pyplot.yticks()

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

Python中的 Matplotlib.pyplot.yticks()

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

Matplotlib.pyplot.yticks()函数

matplotlib 库的 pyplot 模块中的annotate()函数用于获取和设置 y 轴的当前刻度位置和标签。

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

示例 #1:

# Implementation of matplotlib.pyplot.yticks()
# function
  
import numpy as np
import matplotlib.pyplot as plt
    
# values of x and y axes 
valx = [30, 35, 50, 5, 10, 40, 45, 15, 20, 25] 
valy = [1, 4, 3, 2, 7, 6, 9, 8, 10, 5] 
    
plt.plot(valx, valy) 
plt.xlabel('X-axis') 
plt.ylabel('Y-axis') 
    
plt.xticks(np.arange(0, 60, 5)) 
plt.yticks(np.arange(0, 15, 1)) 
plt.show() 

输出:

示例 #2:

#Implementation of matplotlib.pyplot.yticks() 
# function
   
import matplotlib.pyplot as plt
   
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
   
   
def get_demo_image():
    from matplotlib.cbook import get_sample_data
    import numpy as np
    f = get_sample_data("axes_grid/bivariate_normal.npy",
                        asfileobj=False)
    z = np.load(f)
    # z is a numpy array of 15x15
    return z, (3, 19, 4, 13)
   
   
fig, ax = plt.subplots(figsize=[5, 4])
   
Z, extent = get_demo_image()
   
ax.set(aspect=1,
       xlim=(0, 65),
       ylim=(0, 50))
   
   
axins = zoomed_inset_axes(ax, zoom=2, loc='upper right')
im = axins.imshow(Z, extent=extent, interpolation="nearest",
                  origin="upper")
   
plt.xlabel('X-axis') 
plt.ylabel('Y-axis')
   
plt.yticks(visible=False)
   
   
plt.show() 

输出: