python turtle简易绘图(详解Python使用Plotly绘图工具,绘制甘特图)
类别:脚本大全 浏览量:1663
时间:2021-10-23 10:26:03 python turtle简易绘图
详解Python使用Plotly绘图工具,绘制甘特图今天来讲一下如何使用python 的绘图工具plotly来绘制甘特图的方法
甘特图大家应该了解熟悉,就是通过条形来显示项目的进度、时间安排等相关情况的。
我们今天来学习一下,如何使用ployly来绘制甘特图
绘制甘特图的函数为plotly.figure_factoryz中create_gantt方法
通过参数事件task,开始start,结束finish的时间的数据来绘制甘特图
|
import plotly as py import plotly.figure_factory as ff pyplt = py.offline.plot df = [ dict (task = "项目1" , start = '2019-02-01' , finish = '2019-05-28' ), dict (task = "项目2" , start = '2019-03-05' , finish = '2019-04-15' ), dict (task = "项目3" , start = '2019-03-20' , finish = '2019-05-30' )] fig = ff.create_gantt(df) pyplt(fig, filename = 'tmp/1.html' ) |
运行上诉代码,我们可以看到纵坐标为我们的的项目数量。横坐标时间不短增加,越接近纵坐标的,说明事件发生的情况越早。
还可以在甘特图中加入数字索引值
代码如下:
|
import plotly as py import plotly.figure_factory as ff pyplt = py.offline.plot df = [ dict (task = "项目1" , start = '2019-01-01' , finish = '2019-02-28' , complete = 10 ), dict (task = "项目2" , start = '2018-12-05' , finish = '2019-04-15' , complete = 10 ), dict (task = "项目3" , start = '2019-02-20' , finish = '2019-05-30' , complete = 50 ), dict (task = "项目4" , start = '2019-03-20' , finish = '2019-06-30' , complete = 50 ), dict (task = "项目5" , start = '2019-01-12' , finish = '2019-04-28' , complete = 100 ), dict (task = "项目6" , start = '2019-03-07' , finish = '2019-08-21' , complete = 100 )] fig = ff.create_gantt(df, index_col = 'complete' , show_colorbar = true) pyplt(fig, filename = 'tmp/1.html' ) |
运行上诉代码,可以看到右边出现了索引条,每项工作后的complete属性即为其对应的索引值,在create_gamtt函数中
设置,index_col = ‘complete',则会出现相同条形对应相同颜色的,可以根据颜色来盘点任务大概对应的索引值是多少。
这个值得范围0-100,用来反映工作完成的进度,100表示全部完成,0表示没有进展。
接下来讲解如何按照类别来进行索引
|
import plotly as py import plotly.figure_factory as ff pyplt = py.offline.plot df = [ dict (task = "项目1" , start = '2019-01-01' , finish = '2019-02-02' , resource = 'complete' ), dict (task = "项目2" , start = '2019-02-15' , finish = '2019-03-15' , resource = 'incomplete' ), dict (task = "项目3" , start = '2019-01-17' , finish = '2019-02-17' , resource = 'not started' ), dict (task = "项目4" , start = '2019-01-17' , finish = '2019-02-17' , resource = 'complete' ), dict (task = "项目5" , start = '2019-03-10' , finish = '2019-03-20' , resource = 'not started' ), dict (task = "项目6" , start = '2019-04-01' , finish = '2019-04-20' , resource = 'not started' ), dict (task = "项目7" , start = '2019-05-18' , finish = '2019-06-18' , resource = 'not started' ), dict (task = "项目8" , start = '2019-01-14' , finish = '2019-03-14' , resource = 'complete' )] colors = { 'not started' : 'rgb(220, 0, 0)' , 'incomplete' : ( 1 , 0.9 , 0.16 ), 'complete' : 'rgb(0, 255, 100)' } fig = ff.create_gantt(df, colors = colors, index_col = 'resource' , group_tasks = true) pyplt(fig, filename = 'tmp/1.html' ) 运行上诉代码,得到如下图所示内容 |
运行上诉代码,得到如下图所示内容
这里我们通过按照不同的颜色,来分别项目的类型。同一颜色,为同一项目。在每一项数据中
resource代表此项工作所属的状态。这里分了三种状态。
通过在设置create_gantt函数中的index_col = 'resource'即可完成。
color属性用于设置不同状态对应的颜色。
以上所述是小编给大家介绍的python使用plotly绘图工具,绘制甘特图详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对开心学习网网站的支持!
原文链接:https://blog.csdn.net/u012798683/article/details/88852291
您可能感兴趣
- python怎么设置matlab编程(实例详解Matlab 与 Python 的区别)
- python调用支付宝支付接口(python实现支付宝转账接口)
- python 摄像头运用(使用Python控制摄像头拍照并发邮件)
- python如何解压加密zip文件(python读取有密码的zip压缩文件实例)
- python编程面试常见问题(分析经典Python开发工程师面试题)
- python进度条怎么实现(Python小进度条显示代码)
- python如何判断文件是否结束(python判断文件是否存在,不存在就创建一个的实例)
- python时间类的实现(Python日期时间Time模块实例详解)
- pythonrequests框架实例(Python requests模块实例用法)
- python列表的循环遍历使用教程(Python中使用遍历在列表中添加字典遇到的坑)
- python模块使用方法(详解python的argpare和click模块小结)
- python里字典常用方法(Python使用字典的嵌套功能详解)
- python怎么进行参数传递(在Python中如何传递任意数量的实参的示例代码)
- python 取出时间段日志(python 实现提取某个索引中某个时间段的数据方法)
- python分析excel基础数据生成报表(Python实现定制自动化业务流量报表周报功能XlsxWriter模块)
- python接口管理系统(基于Python实现用户管理系统)
- 数学语文题目(语文的数学题)
- 香蕉(香蕉三种人不宜吃)
- 没钱可以快乐吗(没钱也能快乐吗)
- 快乐是什么(快乐就是)
- 东南亚有哪个国家(东南亚有哪个国家最发达)
- 东南亚安全吗(好不好挣钱)
热门推荐
- thinkphp5如何实现消息队列(thinkPHP5.1框架使用SemanticUI实现分页功能示例)
- docker 增大mysql连接数(docker中修改mysql最大连接数及配置文件的实现)
- ftp文件操作三种类型(详解ftp创建文件权限问题)
- mysql 主从配置详解(MySQL 8.0.15配置MGR单主多从的方法)
- phpstudy服务器怎么设置(phpstudy2018 访问目录服务权限问题)
- 有哪些最好用的云服务器(日本云服务器好不好?日本云服务器有哪些优势?)
- mysql对null值如何理解(MySQL为Null会导致5个问题个个致命)
- javascript怎么生成html控件(JavaScript+html实现前端页面滑动验证2)
- 深入理解mysql索引(MySQL中冗余和重复索引的区别说明)
- linux怎么退出括号模式(Linux使用stty显示修改终端行设置)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9