一 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 学习总结的更多相关文章

  1. JavaWeb学习总结-03 JSP 学习和使用

    一 JSP JSP 是Java Server Pages的缩写,在传统的网页HTML文件中加入 Java 程序片段和JSP标签就构成了JSP网页. 1 JSP与Servlet的生成方式 Servlet ...

  2. 机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理、源码解析及测试

    机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理.源码解析及测试 关键字:决策树.python.源码解析.测试作者:米仓山下时间:2018-10-2 ...

  3. OpenCV 学习笔记03 findContours函数

    opencv-python   4.0.1 1 函数释义 词义:发现轮廓! 从二进制图像中查找轮廓(Finds contours in a binary image):轮廓是形状分析和物体检测和识别的 ...

  4. 编写高质量代码改善python程序91个建议学习01

    编写高质量代码改善python程序91个建议学习 第一章 建议1:理解pythonic的相关概念 狭隘的理解:它是高级动态的脚本编程语言,拥有很多强大的库,是解释从上往下执行的 特点: 美胜丑,显胜隐 ...

  5. [Python 学习]2.5版yield之学习心得 - limodou的学习记录 - limodou是一个程序员,他关心的焦点是Python, DocBook, Open Source …

    [Python 学习]2.5版yield之学习心得 - limodou的学习记录 - limodou是一个程序员,他关心的焦点是Python, DocBook, Open Source - [Pyth ...

  6. 《用Python做HTTP接口测试》学习感悟

    机缘巧合之下,报名参加了阿奎老师发布在"好班长"的课程<用Python做HTTP接口测试>,报名费:15rmb,不到一杯咖啡钱,目前为止的状态:坚定不移的跟下去,自学+ ...

  7. Python自动化培训第一周学习总结

    Python自动化培训第一周学习结束,看视频复习,把作业完成了. 总体来说,开卷有益. 首先,工具真是好东西,能够极大提升效率,也是人区别于动物所在.想起前任大领导对工具的不屑,本质也是对效率的不屑, ...

  8. python实用库:PrettyTable 学习

    python实用库:PrettyTable 学习 PrettyTable说明 PrettyTable 是python中的一个第三方库,可用来生成美观的ASCII格式的表格,十分实用. 以下为官方介绍: ...

  9. OpenCV 学习笔记03 边界框、最小矩形区域和最小闭圆的轮廓

    本节代码使用的opencv-python 4.0.1,numpy 1.15.4 + mkl 使用图片为 Mjolnir_Round_Car_Magnet_300x300.jpg 代码如下: impor ...

随机推荐

  1. [Android]使用Dagger 2依赖注入 - 自定义Scope(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5095426.html 使用Dagger 2依赖注入 - 自定义 ...

  2. [Android]Android端ORM框架——RapidORM(v2.1)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/6020412.html [Android]Android端ORM ...

  3. Fresco从配置到使用(最高效的图片加载框架)

    Frescoj说明:      facebook开源的针对android应用的图片加载框架,高效和功能齐全. 支持加载网络,本地存储和资源图片: 提供三级缓存(二级memory和一级internal ...

  4. 安卓开发之ListAdapter(二)

    今天我们来学习一下ArrayAdapter: ArrayAdapter是安卓中最简单的适配器.使用ArrayAdapter(数组适配器),需要把数据源存 放至数组里面来显示. •构造函数: publi ...

  5. 19-typedef

    本文目录 一.typedef作用简介 二.typedef与指针 三.typedef与结构体 三.typedef与指向结构体的指针 四.typedef与枚举类型 五.typedef与指向函数的指针 六. ...

  6. Yii2 modal中 ajax提交表单

    view: // view 代码 $form = ActiveForm::begin(['id' => $model->formName()]); // js 代码 $js = <& ...

  7. 为什么现在我最终推荐内存OLTP

    在今年的8月份,我写了篇文章,介绍了我还不推荐用户使用内存OLTP的各个理由.近日很多人告诉我,他们有一些性能的问题,并考虑使用内存OLTP来解决它们. 众所皆知,在SQL Server里内存OLTP ...

  8. [转]MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN

    本文转自:http://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 在M ...

  9. HDU 1856 Brave Game(巴什博奕)

    十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻. 今天,大家选择 ...

  10. C语言文法

    C语言文法 源程序 → 外部声明 | 子程序(外部声明) 外部声明   → 函数定义| 函数声明 函数定义 → 类型标识符(复合句) 标识符类型 → 无类型 | 字符型 | 整型 | 浮点型 整型→ ...