一.折线图(某天10点到11点的温度变化情况)

from matplotlib import pyplot as plt
from matplotlib import font_manager
import random
# 找到中文字体存放路径及名称
my_font = font_manager.FontProperties(fname='C:\Windows\Fonts\STFANGSO.TTF')
# 设置x轴
x = range(0, 120)
# 设置y轴
y = [random.randint(20, 35)for i in range(120)]
# 设置大小及清晰程度
plt.figure(figsize=(20, 8), dpi=80)
# 合并想x,y轴
plt.plot(x, y)
# 设置x轴刻度大小
_x = list(x)
_x_detail = ['10点{}分'.format(i)for i in range(60)]
_x_detail += ['11点{}分'.format(i) for i in range(60)]
plt.xticks(_x[::3], _x_detail[::3], rotation=45, fontproperties=my_font)  # rotation旋转度数
# 设置x,y轴所代表的含义以及单位
plt.xlabel('时间/(分钟)', fontproperties=my_font)
plt.ylabel('温度/(摄氏度)', fontproperties=my_font)
# 整个图的含义
plt.title('10.28 10点到11点的温度变化', fontproperties=my_font)

# 保存图片
plt.savefig('./img/6.png')
# # 展示图片
# plt.show()

2.一张表中展示多条折线图(两个人在近几年来,交朋友的情况)

"""
近年来两人交男女朋友的情况
"""
from matplotlib import pyplot as plt
from matplotlib import font_manager

my_font = font_manager.FontProperties(fname='C:\Windows\Fonts\STFANGSO.TTF')
x = range(11, 31)
# 自己
y1 = [1, 0, 1, 1, 2, 6, 3, 2, 3, 4, 2, 3, 1, 5, 6, 4, 3, 2, 0, 1]
# 朋友
y2 = [0, 3, 2, 1, 2, 3, 4, 2, 3, 1, 3, 5, 3, 2, 3, 0, 0, 0, 2, 1]
# 设置大小
plt.figure(figsize=(20,8),dpi=80)
# 设置x,y刻度
plt.xticks(x)
plt.yticks(y1)
plt.yticks(y2)
# 画图
plt.plot(x,y1,label='自己')
plt.plot(x,y2,label='朋友')
# 添加网格,以及调节透明度
plt.grid(alpha=0.2)
# 添加图例
plt.legend(prop=my_font,)
plt.savefig('./img/8.png')

3.散点图(plt.scatter)

01-01 02:40