首先,全局引入需要的库和字体设置
import random
from matplotlib import pyplot as plt
import matplotlib
font = {
- ‘family’:‘SimHei’,
‘weight’:‘bold’,
‘size’:12
}
matplotlib.rc(“font”, **font)
案例1.假设通过爬虫你获取到了长沙2019年4,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温和随时间变化的某种规律
x_4 = range(1,32)
x_10 = range(51,82)
y_4 = [11,17,16,11,12,11,12,13,10,14,8,13,12,15,14,17,18,21,
16,17,30,14,15,15,15,19,21,22,22,22,23]
y_10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,
21,20,22,15,11,15,5,13,15,10,11,13,12,13,6]
plt.figure(figsize=(10,8))
plt.scatter(x_4,y_4)
plt.scatter(x_10,y_10)
x_t = list(x_4)+list(x_10)
x_l = [f"四月{i}日" for i in x_4]
x_l += [f"十月{i-50}日" for i in x_10]
plt.xticks(x_t[::3],x_l[::3],rotation=75)
plt.xlabel