Grid of python data visualization matplotlib

grid() – grid lines

No video link yet
insert image description here

Function format:

plt.grid(linestyle=":",color="r")

Parameter Description:

  • linestyle: grid line style
  • -:solid line style
  • –:dashed line style
  • -.:dash-dot line style
  • ::dotted line style
  • color: grid line color

code:

import matplotlib.pyplot as plt
import numpy as np
# 准备数据
x = np.linspace(0.05,10,100)
y = np.sin(x)
# 画线条
plt.plot(x,y,ls=":",label="plot")

# 网格线
plt.grid(ls=":",c='r')

# 显示图例
plt.legend()
# 显示图形,必须的
plt.show()

Guess you like

Origin blog.csdn.net/wudechun/article/details/105896864