这是一篇关于plotly的简单介绍文章,我会在这里以链接和短代码的形式简单介绍plotly的使用。需要注意plotly需要搭配jupyter notebook使用
jupyter notebook的安装:1、打开anaconda prompt ,2、conda install -c conda-forge notebook
如果是pip:pip install notebook
jupyter notebook的启动:win+r命令行窗口 jupyter notebook需要注意使用过程中的命令行窗口不能关闭。
首先是官网:Getting Started with Plotlyplot.ly
不推荐大家看各种网文攻略,质量很差,慢慢对着官网敲效果好很多。
其次Githubhttps://github.com/plotly/plotly.pygithub.com
plotly在jupyter下使用需要安装渲染器,同时不同的表格需要不同的库,GitHub这一页基本都有介绍。
具体使用:
plotly提供两种设置图像参数的方法,第一种是python中的字典,第二种是"graph objects"。下面两段短代码生成的图像是一样的:
fig = {
"data": [{"type": "bar",
"x": [1, 2, 3],
"y": [1, 3, 2]}],
"layout": {"title": {"text": "A Bar Chart"}}
}
# To display the figure defined by this dict, use the low-level plotly.io.show function
import plotly.io as pio
pio.show(fig)
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
layout=go.Layout(
title=go.layout.Title(text="A Bar Chart")
)
)
fig.show()
设置底色和水印教程:Theming and templatesplot.ly
以及简单图像的地图示例:全球人口分布的bubble图
import plotly.express as px
df = px.data.gapminder().query("year==2007")
fig = px.scatter_geo(df, locations="iso_alpha", color="continent",
hover_name="country", size="pop",
projection="natural earth")
fig.show()
实操案例:https://plot.ly/python/visualizing-mri-volume-slices/plot.ly
最后贴一个还不错的文章http://www.pianshen.com/article/5500341648/www.pianshen.com
后面我会在实际处理数据后更新相关使用的方法和自己的源码。
今天开始数据可视化学习算是正式提上了日程吧,一点点做笔记,慢慢来。