Python 简单快速折线图,绘图、报表 教程

来源:互联网 发布:微信直播 阿里云 编辑:程序博客网 时间:2024/05/16 19:55

Python 简单快速折线图,绘图、报表 教程


安装 matplotlib 模块

  • pip命令
    pip3 install matplotlib

实例

10天销售额折线图

  • 数据
日期 销售额 1号 135.53 2号 150.32 3号 159.53 4号 596.31 5号 315.13 6号 950.32 7号 153.53 8号 536.21 9号 958.31 10号 215.53

代码实现

import matplotlib.pyplot as pltx = [i for i in range(1,11)] # 添加10个日期y = [135.53, 150.32, 159.53, 596.31, 315.13, 950.32,     153.53, 536.21, 958.31, 215.53] # 模拟在数据库的数据plt.plot(x, y) # 绘制plt.title('10天销售额') # 标题plt.xlabel('日期') # x标签名plt.ylabel('销售额') # y标签名for xy in zip(x,y):    plt.annotate(xy[1], xy=xy, xytext=(0,0), textcoords = 'offset points') # 后面说明参数用处plt.show() # 显示

效果

这里写图片描述

plt.annotate()用到的参数说明

  • plt.annotate(xy[1], xy=xy, xytext=(0,0), textcoords = 'offset points')
  • 第一个参数:标注的标题
  • 第二个参数:标注标题的 x y 坐标位置
  • 第三个参数:标题以第二个参数xy位置显示,为坐标的(0,0),来调整标题的第一个字符的位置。 自行更改坐标参数体验
1 0
原创粉丝点击