Python学习总结 03 Plotly 学习总结
一 Plotly 简介

Plotly是另一个免费进行数据分析和绘制图表的APP,建立在d3.js上。 Plotly图可下载为SVG,EPS或PNG格式,并简单地导入到Illustrator或者Photoshop中。详细内容可以去官网参考:
https://plot.ly/python/
1 安装
安装Plotly的Python安装包,需要使用pip命令来安装,安装命令如下。
sudo pip install plotly
如果安装成功会下图所示。

如果要升级Plotly模块,使用以下命令来升级。
pip install plotly --upgrade
2 初始化在线绘图
Plotly提供了在线服务,首先需要去以下的官网去注册一个账号
https://plot.ly/ssu/
然后在线生成一个私钥 API Key, 这里可以使用我已经注册的账户和私钥。
账户: templarz
API Key : PtKMjV9gAzINZqmQRU4T
在python交互环境下运行以下初始化命令,生成认证的安全文件 .plotly/.credentials。
import plotly
plotly.tools.set_credentials_file(username='templarz', api_key='PtKMjV9gAzINZqmQRU4T')
初始化生成的Plotly的安全文件.plotly/.credentials在home目录下,在~/.plotly/.credentials下。在文件中会看到以下内容,就说明初始化命令起作用了。
{
"username": "templarz",
"stream_ids": [],
"api_key": "PtKMjV9gAzINZqmQRU4T",
"proxy_username": "",
"proxy_password": ""
}~
注意:
文中使用的开发环境是Ubuntu,如果是在Windows环境生成的安全文件,那么它所在的位置会有所不同。
3 例子1 生成在线折线图
当使用Plotly web服务时,生成的plot和数据会保存到你的云账户中,下面的例子运行后会生成一个独一无二的url地址,通过这个地址可以访问你生成的plot图形。
import plotly.plotly as py
from plotly.graph_objs import * trace0 = Scatter(
x=[, , , ],
y=[, , , ]
)
trace1 = Scatter(
x=[, , , ],
y=[, , , ]
)
data = Data([trace0, trace1]) py.plot(data, filename = 'basic-line')
运行以上那段代码后,会生成在浏览器中打开地址https://plot.ly/%7Etemplarz/4/ 地址,在云账户templarz中显示生成的plot图形如下图所示。

使用以下命令查看py.plot的api使用方法。
import plotly.plotly as py
help(py.plot)
输入后得到以下消息提示。
Help on function plot in module plotly.plotly.plotly: plot(figure_or_data, validate=True, **plot_options)
Create a unique url for this plot in Plotly and optionally open url. plot_options keyword agruments:
filename (string) -- the name that will be associated with this figure
fileopt ('new' | 'overwrite' | 'extend' | 'append') -- 'new' creates a
'new': create a new, unique url for this plot
'overwrite': overwrite the file associated with `filename` with this
'extend': add additional numbers (data) to existing traces
'append': add additional traces to existing data lists
auto_open (default=True) -- Toggle browser options
True: open this plot in a new browser tab
False: do not open plot in the browser, but do return the unique url
sharing ('public' | 'private' | 'secret') -- Toggle who can view this
graph
- 'public': Anyone can view this graph. It will appear in your profile
and can appear in search engines. You do not need to be
logged in to Plotly to view this chart.
- 'private': Only you can view this plot. It will not appear in the
Plotly feed, your profile, or search engines. You must be
logged in to Plotly to view this graph. You can privately
share this graph with other Plotly users in your online
Plotly account and they will need to be logged in to
view this plot.
- 'secret': Anyone with this secret link can view this chart. It will
not appear in the Plotly feed, your profile, or search
engines. If it is embedded inside a webpage or an IPython
notebook, anybody who is viewing that page will be able to
view the graph. You do not need to be logged in to view
this plot.
world_readable (default=True) -- Deprecated: use "sharing".
Make this figure private/public >>>
资料参考:
https://plot.ly/python/getting-started/
http://www.cnblogs.com/chaosimple/p/4153083.html
Python学习总结 03 Plotly 学习总结的更多相关文章
- JavaWeb学习总结-03 JSP 学习和使用
一 JSP JSP 是Java Server Pages的缩写,在传统的网页HTML文件中加入 Java 程序片段和JSP标签就构成了JSP网页. 1 JSP与Servlet的生成方式 Servlet ...
- 机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理、源码解析及测试
机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理.源码解析及测试 关键字:决策树.python.源码解析.测试作者:米仓山下时间:2018-10-2 ...
- OpenCV 学习笔记03 findContours函数
opencv-python 4.0.1 1 函数释义 词义:发现轮廓! 从二进制图像中查找轮廓(Finds contours in a binary image):轮廓是形状分析和物体检测和识别的 ...
- 编写高质量代码改善python程序91个建议学习01
编写高质量代码改善python程序91个建议学习 第一章 建议1:理解pythonic的相关概念 狭隘的理解:它是高级动态的脚本编程语言,拥有很多强大的库,是解释从上往下执行的 特点: 美胜丑,显胜隐 ...
- [Python 学习]2.5版yield之学习心得 - limodou的学习记录 - limodou是一个程序员,他关心的焦点是Python, DocBook, Open Source …
[Python 学习]2.5版yield之学习心得 - limodou的学习记录 - limodou是一个程序员,他关心的焦点是Python, DocBook, Open Source - [Pyth ...
- 《用Python做HTTP接口测试》学习感悟
机缘巧合之下,报名参加了阿奎老师发布在"好班长"的课程<用Python做HTTP接口测试>,报名费:15rmb,不到一杯咖啡钱,目前为止的状态:坚定不移的跟下去,自学+ ...
- Python自动化培训第一周学习总结
Python自动化培训第一周学习结束,看视频复习,把作业完成了. 总体来说,开卷有益. 首先,工具真是好东西,能够极大提升效率,也是人区别于动物所在.想起前任大领导对工具的不屑,本质也是对效率的不屑, ...
- python实用库:PrettyTable 学习
python实用库:PrettyTable 学习 PrettyTable说明 PrettyTable 是python中的一个第三方库,可用来生成美观的ASCII格式的表格,十分实用. 以下为官方介绍: ...
- OpenCV 学习笔记03 边界框、最小矩形区域和最小闭圆的轮廓
本节代码使用的opencv-python 4.0.1,numpy 1.15.4 + mkl 使用图片为 Mjolnir_Round_Car_Magnet_300x300.jpg 代码如下: impor ...
随机推荐
- Oracle Sales Cloud:报告和分析(BIEE)小细节1——创建双提示并建立关联(例如,部门和子部门提示)
Oracle Sales Cloud(Oracle 销售云)是一套基于Oracle云端的客户商机管理系统,通过提供丰富的功能来帮助提高销售效率,更好地去了解客户,发现和追踪商机,为最终的销售成交 (d ...
- react-native DatePicker日期选择组件的实现
本教程的实现效果如下: 为了实现其淡入/淡出的覆盖效果, 还有取消按钮, 在此用了一个三方的组件, 大家可以先安装一下: 三方组件的地址:https://github.com/eyaleizenber ...
- iOS平台UDID方案比较
苹果在iOS6中禁用了[UIDevice uniqueIdentifier],在iOS7中又把mac地址的获取给堵上了.没办法,毕竟人家是老大,说不让你用,你也没办法.在这边总结一下现有的一部分UDI ...
- 解决apache启动错误"httpd:Could not reliably determine..."
启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name [root@serv ...
- zend studio 快捷键
复制当前行:ctrl+alt+↓ 删除当前行:Ctrl+d 行注释:Ctrl+/ 快注释(先选中要注释的代码):Ctrl+shift+/ 提示助手(方便函数等补全):alt+/ 代码格式化:Ctrl+ ...
- 【译】Spring 4 + Hibernate 4 + Mysql + Maven集成例子(注解 + XML)
前言 译文链接:http://websystique.com/spring/spring4-hibernate4-mysql-maven-integration-example-using-annot ...
- 尝试解析js面试题(二)
说明:一共有13题(原本14题,最后一道什么鬼,嫌弃不要了),覆盖面比较广,都属于比较烧脑的类型,各种神坑:不过对于夯实js理论基础帮助非常大:看看都能做对几题吧(
- Oracle/PLSQL: ORA-06550
参考: http://blog.csdn.net/haiross/article/details/20612135 Oracle/PLSQL: ORA-06550 Learn the cause an ...
- SQL语句中的where 1=1 和0=1
摘自:http://blog.sina.com.cn/s/blog_afe616ab0101camd.html SQL where 1=1 和0=1的作用 where 1=1; 这个条件始终为True ...
- Redux状态管理方法与实例
状态管理是目前构建单页应用中不可或缺的一环,也是值得花时间学习的知识点.React官方推荐我们使用Redux来管理我们的React应用,同时也提供了Redux的文档来供我们学习,中文版地址为http: ...