Matplotlib基本图形之折线图

折线图特点 折线图是用折线将各数据连起来组成的图形
常用来观察数据随时间变化的趋势
例如:股票价格,温度变化,等等 示例代码:
import os
import time
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates basedir = os.path.dirname(os.path.abspath(__file__))
resultdir = os.path.join(basedir, 'result') class Create_plot(object): def __init__(self,data1,data2,dst,name='',title='Title',color='r',mark='o',alpha=1):
''' :param data1: x轴使用的数据,一般为列表
:param data2: y轴使用的数据,一般为列表
:param dst: 存放生成图片的文件夹路径
:param name: 图片的名称,默认为当前时间戳
:param title: 图片的标题,默认为Title
:param c: 图片的颜色,默认为红色
:param mark: 图片点的形状,默认为圆形
:param alpha: 点的透明度,默认为1,即不透明
'''
self.x = data1
self.y = data2
self.dst = dst
self.name = name if name else str(int(time.time()))
self.title = title
self.color = color
self.marker = mark
self.alpha = alpha def drew_normal(self):
plt.plot(
self.x,
self.y,
color = self.color,
marker=self.marker,
alpha = self.alpha
)
plt.title(self.title)
picname = self.name+'.jpg'
picdir = os.path.join(self.dst, picname)
plt.savefig(picdir) def drew_date(self):
plt.plot_date(
self.x,
self.y,
color = self.color,
marker=self.marker,
alpha = self.alpha,
linestyle = '-'
)
plt.title(self.title)
picname = self.name+'.jpg'
picdir = os.path.join(self.dst, picname)
plt.savefig(picdir)
# plt.show()

绘制基本折线图

temp = [2,4,7,10,11,13,15,18,17,13,10,7]
hour = [0,2,4,6,8,10,12,14,16,18,20,22] PIC = Create_plot(hour,temp,resultdir)
PIC.drew_normal()

结果如下:

绘制日期格式折线图

money = [100,500,800,600,300]
date = ['2018/6/1','2018/7/1','2018/8/1','2018/9/1','2018/10/1']
strconverter = mdates.strpdate2num('%Y/%m/%d')
date = [strconverter(x) for x in date] PIC = Create_plot(date, money,resultdir)
PIC.drew_date()

结果如下:

Matplotlib基本图形之折线图的更多相关文章

  1. 【学习总结】GirlsInAI ML-diary day-21-初识 Numpy, Matplotlib, Seanborn [柱状图、折线图、箱图]

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day21 初识 Numpy, Matplotlib, Seanborn [柱状图.折线图.箱图] 一.Titanic练习赛 ...

  2. VS2010 使用TeeChart画图控件 - 之二 - 绘制图形(折线图,柱状图)

    1.前期准备 详细可见VS2010 使用TeeChart画图控件 - 之中的一个 控件和类的导入 1. 1 加入TeeChart控件,给控件加入变量m_TeeChart 加入TeeChart控件,右击 ...

  3. python中matplotlib绘图封装类之折线图、条状图、圆饼图

    DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...

  4. VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)

    1.前期准备 具体可见VS2010 使用TeeChart绘图控件 - 之一 控件和类的导入 1. 1 添加TeeChart控件,给控件添加变量m_TeeChart 添加TeeChart控件,右击控件, ...

  5. python使用matplotlib绘制折线图教程

    Matplotlib是一个Python工具箱,用于科学计算的数据可视化.借助它,Python可以绘制如Matlab和Octave多种多样的数据图形.下面这篇文章主要介绍了python使用matplot ...

  6. Python开发【模块】:matplotlib 绘制折线图

    matplotlib 1.安装matplotlib ① linux系统安装 # 安装matplotlib模块 $ sudo apt-get install python3-matplotlib # 如 ...

  7. matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图

    一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...

  8. 使用matplotlib绘图(一)之折线图

    # 使用matplotlib绘制折线图 import matplotlib.pyplot as plt import numpy as np # 在一个图形中创建两条线 fig = plt.figur ...

  9. 【Python】matplotlib绘制折线图

    一.绘制简单的折线图 import matplotlib.pyplot as plt squares=[1,4,9,16,25] plt.plot(squares) plt.show() 我们首先导入 ...

随机推荐

  1. CodeSmith Generator 7.0.2

    [工具]CodeSmith Generator 7.0.2激活步骤 只看楼主 收藏 回复     M炎骫毒逆天T   c#攻城狮 8   学过三层的人应该认识CodeSmith Generator吧, ...

  2. 【js】数组去重时间复杂度为n的方法

    # 时间复杂度O(n^2) function fn(arr) { return arr.filter((item, index, arr) => arr.indexOf(item) === in ...

  3. FPGA的嵌入式RAM

    FPGA中的嵌入式RAM分为两种:专用的BRAM和分布是RAM(用LUT实现的).这两种RAM又可以配置成单端口和双端口的RAM和ROM.双端口RAM又可以根据读写地址是否在同一块分为Double P ...

  4. apache安装报错

    libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending /some_directory ...

  5. Python实现扫描作业配置自动化

    持续集成平台接入扫描作业是一项繁琐而又需要细致的工作,于是趁着闲暇时间,将代码扫描作业用Python代码实现了配置自动化. 每次配置作业的过程中,都会在checkcode1或者checkcode3上 ...

  6. 使用 Azure 创建网络文件系统

    本快速入门介绍了如何使用 Azure 文件存储实现网络文件共享.在本教程中完成的所有操作均符合 1 元试用条件. 本快速入门介绍了如何使用 Azure 文件存储实现网络文件共享.在本教程中完成的所有操 ...

  7. ScriptManager对象的属性

    --<本文属于摘抄> 属性 说明 EnablePageMethods 指定在ASPX页面上定义的公共静态方法是否可以从客户端脚本中作为Web服务方法调用 EnablePartialRend ...

  8. 洛谷 P2984 [USACO10FEB]给巧克力Chocolate Giving

    题目描述 Farmer John is distributing chocolates at the barn for Valentine's day, and B (1 <= B <= ...

  9. (二)mybaits之ORM模型

    前言:为什么还没有进入到mybatis的学习呢?因为mybatis框架的核心思想就是ORM模型,所以好好了解一下ORM模型是有必要哒. ORM模型   ORM(Object Relational Ma ...

  10. com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.168.1.13:20881, cause: Failed to bind to: /0.0.0.0:20881

    抛出的异常如上,解决方案是:根据异常信息确定是端口被占用,排查项目是否启动之后没有关闭,在windows命令行中运行如下命令:netstat -ano 检查端口占用的情况,根据pid在任务管理器中杀死 ...