python学习之折线图

43 阅读1分钟

image.png

安装绘图数据库

python -m pip install --user matplotlib

核心代码

# 绘制折线图
import matplotlib.pyplot as plt
# 这里输入输出 数据长度要一致
squares = [0,1,4,9,16,25]
input_values = [0,1,2,3,4,5,]
fig,ax = plt.subplots()

# 生成绘图
# linewidth 折现宽度
# 同时提供输入输出参数, 改变坐标默认为0的情况
ax.plot(input_values,squares, linewidth=5)
# 表title
ax.set_title('Square Numbers', fontsize=24)
# 横轴
ax.set_xlabel('Value', fontsize=14)
# 纵轴标题
ax.set_ylabel('Square of Value', fontsize=14)
# 设置刻度标记的样式
ax.tick_params(labelsize=14)
plt.show()