matpltlib可视化之自定义x、y轴数据和背景分段填充,改变全局字体大小

import numpy as np
import matplotlib.pyplot as plt

import matplotlib
import matplotlib.pyplot as plt

matplotlib.rcParams.update({'font.size':24 }) # 改变所有字体大小,改变其他性质类似
plt.figure(figsize=(12,8))

x = [i for i in range(0,120)]
y1 = df_17_in_out['in']
y2 = df_17_in_out['out']
plt.plot(x, y1, label='to')
plt.plot(x, y2, label='from')

#将x轴置空

plt.xticks(x,())

#用需要的数据将x轴替换为需要的数据

plt.xticks((0,31,76,101,119), ('Dec.01','Jan.01','Feb.16','Mar.13','Mar.31'))
# 垂直填充
plt.axvspan(0,31, facecolor='#C0C0C0', alpha=0.5)
plt.axvspan(31,76, facecolor='#FFFFFF', alpha=0.5)
plt.axvspan(76,101, facecolor='#C0C0C0', alpha=0.5)
plt.axvspan(101,119, facecolor='#FFFFFF', alpha=0.5)
plt.ylabel('and from wuhan (%)')
plt.legend()
plt.savefig('./01.pdf')
plt.show()
matpltlib可视化之自定义x、y轴数据和背景分段填充,改变全局字体大小_第1张图片

你可能感兴趣的:(可视化)