https://matplotlib.org/stable/plot_types/index.html
由Matplotlib官网资料学习,逐句分析解释。
一,曲线图绘制
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
'''为设置背景样式,其中Matplotlib包含多种样式可供选择或替换如
['bmh', 'classic', 'dark_background', 'fast',
'fivethirtyeight', 'ggplot', 'grayscale',]'''
# make data
x = np.linspace(0, 10, 100)#为生成从0到10的100个等差均匀数列
y = 4 + 2 * np.sin(2 * x)
# plot
fig, ax = plt.subplots()
'''fig-------即figure,画窗
ax-------即axex,画窗中创建的笛卡尔坐标区
原句是下面语句的简写
fig = plt.figure()#首先调用plt.figure()创建了一个**画窗对象fig**
ax = fig.add_subplot(111)#然后再对fix创建默认的坐标区(一行一列一个坐标区)
'''
ax.plot(x, y, linewidth=2.0)#绘制以x为横坐标,y为纵坐标,线条粗细为2的图像
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
#xlim为所绘制曲线的范围,xticks为画窗格中展示的范围
# 若画窗格的范围大于图像的范围则以空白展示
plt.show()#展示图像