📜  Python中的 Matplotlib.pyplot.grid()

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

Python中的 Matplotlib.pyplot.grid()

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

matplotlib.pyplot.grid()函数

matplotlib 库的 pyplot 模块中的grid()函数用于配置网格线。

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

示例 #1:

# Implementation of matplotlib function   
import matplotlib.pyplot as plt
import numpy as np
      
plt.plot([1, 2, 3])
plt.grid()
  
plt.title('matplotlib.pyplot.grid() function \
Example\n\n', fontweight ="bold")
plt.show()

输出:

示例 #2:

# Implementation of matplotlib function   
import numpy as np
import matplotlib.pyplot as plt
  
np.random.seed(19680801)
  
val, res = 100, 15
x = np.sin(val + res * np.random.randn(10000)) - np.cos(val + res * np.random.randn(10000))
  
n, bins, patches = plt.hist(x, 200, 
                            density = True, 
                            facecolor ='g', 
                            alpha = 0.5)
  
plt.grid(True)
  
plt.title('matplotlib.pyplot.grid() function \
Example\n\n', fontweight ="bold")
  
plt.show()

输出: