一 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. 浏览器渲染引擎,提高css渲染速度。

    一.渲染引擎渲染引擎的职责是……渲染,也就是把请求的内容显示到浏览器屏幕上.默认情况下渲染引擎可以显示HTML,XML文档以及图片. 通过插件(浏览器扩展)它可以显示其它类型文档. 二.各种渲染引擎我 ...

  2. mysql 自定义函数

    原文:http://www.cnblogs.com/zhangminghui/p/4113160.html 引言 MySQL本身提供了内置函数,这些函数的存在给我们日常的开发和数据操作带来了很大的便利 ...

  3. mysql数据类型

    一.数值类型 Mysql支持所有标准SQL中的数值类型,其中包括严格数据类型(INTEGER,SMALLINT,DECIMAL,NUMBERIC),以及近似数值数据类型(FLOAT,REAL,DOUB ...

  4. 如何在mac上用终端打开XAMPP自带的MySQL

    注:1.本文未经博主同意,不得转载! 2.所有终端语句都分行显示,以免大家看错: 直接开始,过程中对每一步可能出现的错误都进行了说明. 1.安装好xampp,然后打开终端,输入: mysql -u r ...

  5. QString::​arg的用法

    1.用法示例1 String str = QString("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11").arg("1"," ...

  6. Unity性能优化(2)-官方教程Diagnosing performance problems using the Profiler window翻译

    本文是Unity官方教程,性能优化系列的第二篇<Diagnosing performance problems using the Profiler window>的简单翻译. 相关文章: ...

  7. ScrollView分栏视图分析

    代码精华部分如下: //1.添加scrollView /* 1). 添加一个scrollView; 2).创建关注.热门.附近三个控制器. 3). 存储它们的名字到数组中,遍历并放到本控制器里. 4) ...

  8. [LeetCode] Hamming Distance 汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  9. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  10. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...