本文中介绍了Plotly
中的多种图形主题的效果,自己一般用的都是默认的主题;FigureWidget
是一个比较好的功能,可以往空白图中依次添加图形,图形也是叠加出现。
如果是Figure
的话,是先把数据处理号,再添加进入后一次性生成全部的图形,FigureWidget
是逐个加入。
主要的主题包含下面几种:
import plotly.io as pio
pio.templates
Templates configuration
-----------------------
Default template: 'plotly'
Available templates:
['ggplot2', 'seaborn', 'simple_white', 'plotly',
'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
'ygridoff', 'gridon', 'none']
import plotly.express as px
df = px.data.gapminder()
df_2007 = df.query("year==2007")
for template in ["plotly", "plotly_white", "plotly_dark", "ggplot2", "seaborn", "simple_white", "none"]:
fig = px.scatter(df_2007,
x="gdpPercap", y="lifeExp", size="pop", color="continent",
log_x=True, size_max=60,
template=template, title="Gapminder 2007: '%s' theme" % template)
fig.show()
FigureWidget
是最近发现的Plotly的功能,其功能可以概括为:conf生成的空白图开始,添加给定数据,再生成需要的图形