## linux:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
data['visit_month'] = pd.to_datetime(data['visit_month'],format='%Y-%m-%d')
df21 = data[(data['review_type']=='video') & (data['high_review']==1)]
df22 = data[(data['review_type']=='video') & (data['high_review']==0)]
fig2 = plt.figure()
ax2 = fig2.add_subplot(1,1,1)
plt.rcParams['font.sans-serif']=['SimHei'] ##正确显示汉字
plt.rcParams['axes.unicode_minus']=False
xfmt = mdates.DateFormatter('%Y-%m') ##正确显示时间序列
ax2.xaxis.set_major_formatter(xfmt)
plt.xticks(np.array(df11['visit_month']),rotation=45) ##旋转角度
ax2.plot(df21['visit_month'],df21['avg_next_course'],'r')
ax2.plot(df21['visit_month'],df22['avg_next_course'],'b')
ax2.plot(df21['visit_month'],df21['avg_review'],'r--')
ax2.plot(df21['visit_month'],df22['avg_review'],'b--')
plt.legend()
plt.title('xx与yy的关系')
plt.savefig('test.png')
##plt.show()
matplotlib_linux作图_时间序列
最新推荐文章于 2022-02-08 23:55:44 发布