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')
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/

王成军
传播学博士,南京大学新闻传播学院助理研究员。集智俱乐部科学委员会成员。曾参与翻译《社会网络分析:方法与实践》(2013),合著《社交网络上的计算传播学》(2015)。对数据科学感兴趣,主要采用python和R编程,写了一个R包networkdiffusion和两个python包:iching 和scholarNetwork。2014年创立并维护计算传播学网站。研究领域:计算传播学,致力于采用计算社会科学地研究方法分析人类传播行为,具体包括社会化媒体与信息扩散、公共讨论、注意力流动、互联网数据挖掘等。

Latest posts by 王成军 ( see all )
使用plotly.py进行数据可视化初步 - 2016年6月28日 计算新闻传播学2016课程资料发布(代码、数据、PPT) - 2016年5月24日 中国交通事故媒介日记 - 2016年4月25日