Python数据可视化—折线图

折线图

也称为趋势图,它使用直线线段将个数据点连接起来而组成的图形,以折线方式显示数据的变化趋势。

 

    折线图绘制函数:

     plot(x,y,style,color,linewidth)

     title(“图的标题”)

    参数说明:

     √ style,画线的样式

     √ color,画线的颜色

     √ linewidth,线的宽度

 

 1 import pandas
 2 import matplotlib
 3 from matplotlib import pyplot as plt
 4 
 5 data=pandas.read_csv(
 6                      "D://Python//6.2//data.csv")
 7 
 8 #对日期格式进行转换
 9 data["购买日期"]=pandas.to_datetime(
10      data["日期"])
11 
12 mainColor=(42/256, 87/256, 141/256, 1)
13 
14 font={
15       "size":20,
16       "family":"SimHei"}
17       
18 matplotlib.rc("font",**font)
19 
20 
21 
22 #%matplotlib qt
23 plt.xlabel(
24            "购买日期",
25            color=mainColor)
26 plt.ylabel(
27            "购买用户数",
28            color=mainColor)
29 
30 plt.tick_params(
31                 axis="x",
32                 colors=mainColor)
33 plt.tick_params(
34                 axis="y",
35                 colors=mainColor)
36 
37 #"-"  顺滑的曲线
38 plt.plot(
39          data["购买日期"],
40          data["购买用户数"],
41           "-",color=mainColor)
42 
43 plt.title("用户天数")
44 plt.show()
45 
46 
47 #设置线条粗细
48 plt.plot(
49          data["购买日期"],
50          data["购买用户数"],
51          "-",color=mainColor,
52          linewidth=10)
View Code

 

posted @ 2018-08-02 15:44  我不要被你记住  阅读(10141)  评论(0编辑  收藏  举报