Fork me on GitHub

plotly-express-21-theme-and-FigureWidget

plotly-express-21-theme and Figurewidget

本文中介绍了Plotly中的多种图形主题的效果,自己一般用的都是默认的主题;FigureWidget是一个比较好的功能,可以往空白图中依次添加图形,图形也是叠加出现。

如果是Figure的话,是先把数据处理号,再添加进入后一次性生成全部的图形,FigureWidget是逐个加入。

不同的主题

主题

主要的主题包含下面几种:

1
2
3
4
5
6
7
8
9
10
11
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']

实例

1
2
3
4
5
6
7
8
9
10
11
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

原理

FigureWidget是最近发现的Plotly的功能,其功能可以概括为:conf生成的空白图开始,添加给定数据,再生成需要的图形

  • 生成一个空白图
  • 添加数据,生成指定的图形
  • 修改数据,更新图形

demo

生成空白的图形

image-20200801202440132

添加折线图

添加柱状图

添加标题

image-20200801202817382

更新数据

image-20200801203341078

image-20200801203559673

本文标题:plotly-express-21-theme-and-FigureWidget

发布时间:2020年08月01日 - 20:08

原始链接:http://www.renpeter.cn/2020/08/01/plotly-express-21-theme-and-FigureWidget.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea