plotly.js

Plotly.js已经开源了,可以在线下生成独立的html文件,因此现在通过python使用plotly完全免费了。本文介绍基于python使用plotly的方法。

Plotly for Python is now entirely open source, free, and self-hosted

安装方法

pip install plotly

需要升级的话,可以输入:

pip install plotly –upgrade

使用方法

最简单的使用方法是参照plotly网站给出的案例,见这里(https://plot.ly/python/

Initialization for Online Plotting

如果不上传到plotly网站,此处可以忽略。

import plotly 
plotly.tools.set_credentials_file(username='your-name', api_key='your-pass-word')

Initialization for Offline Plotting

  • Use plotly.offline.plot() to create and standalone HTML that is saved locally and opened inside your web browser.
  • Use plotly.offline.iplot() when working offline in a Jupyter Notebook to display the plot in the notebook.

数据准备

trace0 = Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
data = Data([trace0, trace1])

plotly.offline.plot

plotly.offline.plot(data, filename = '/Users/chengjun/GitHub/cjc2016/vis/basic-line.html')

basic-line

cheatsheet

更多简单的使用参见:
https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf

Plotly Python resources:

  • Plotly matplotlib figure converter — https://plot.ly/matplotlib/getting-started/
  • Using Plotly with Python offline — https://plot.ly/python/offline/
  • Saving static images (PNG, PDF, etc) — https://plot.ly/python/static-image-export/
  • Creating HTML or PDF reports in Python — https://plot.ly/python/#report-generation
  • Security & Plotly’s server at your company — https://plot.ly/products/on-premise/
  • Creating dashboards with Plotly and Python — https://plot.ly/python/dashboard/
  • Connecting to databases — https://plot.ly/python/#databases
  • Plotly and IPython / Jupyter notebook — https://plot.ly/ipython-notebooks/
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值