x:指定折线图的x轴数据;
y:指定折线图的y轴数据;
linestyle:指定折线的类型,可以是实线、虚线、点虚线、点点线等,默认为实线;
linewidth:指定折线的宽度
marker:可以为折线图添加点,该参数是设置点的形状;
markersize:设置点的大小;
markeredgecolor:设置点的边框色;
markerfactcolor:设置点的填充色;
label:为折线图添加标签,类似于图例的作用;
# 导入模块
import pandas as pd
import matplotlib.pyplot as plt
# 设置绘图风格
plt.style.use('ggplot')
# 设置中文编码和负号的正常显示
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 读取需要绘图的数据
article_reading = pd.read_excel('wechart.xlsx')
# print(article_reading)
# 取出8月份至9月28日的数据
sub_data = article_reading.loc[article_reading.date >= '2017-08-01' ,:]
# print(sub_data)
# 设置图框的大小
fig = plt.figure(figsize=(9,6))
# 绘图
plt.plot(sub_data.date, # x轴数据
sub_data.article_reading_cnts, # y轴数据
linestyle = '-', # 折线类型
linewidth = 2, # 折线宽度
color = 'steelblue', # 线的颜色
marker = 'o', # 点的形状
markersize = 6, # 点的大小
markeredgecolor='red', # 点边框色
markerfacecolor='blue') # 点填充色
# 添加标题和坐标轴标签
plt.title('公众号每天阅读人数趋势图')
plt.xlabel('日期')
plt.ylabel('人数')
# 剔除图框上边界和右边界的刻度
plt.tick_params(top = 'off', right = 'off')
# 为了避免x轴日期刻度标签的重叠,设置x轴刻度自动展现,并且65度倾斜
fig.autofmt_xdate(rotation = 65) # 设置x轴时间外观
# 显示图形
plt.show()