python - Plot.ly 在子图上绘制参考线?
问题描述
我编写了下面的函数来在图形上制作垂直参考线。
from plotly import graph_objects as go
import plotly.express as px
def add_vline(fig, x=0, text=None):
if text is None:
text = str(x)
fig.update_layout(
shapes=list(fig.layout.shapes) + [
go.layout.Shape(
type="line",
x0=x,
x1=x,
yref="paper",
y0=0,
y1=1,
line=dict(
color="Red",
width=2
)
)
],
annotations=list(fig.layout.annotations) + [
go.layout.Annotation(
x=x,
y=0.5,
yref="paper",
text=text
)
]
)
gapminder = px.data.gapminder()
for continent in gapminder.continent.unique():
fig = px.histogram(gapminder, x="lifeExp", title=f'Life expectancy in {continent}')
add_vline(fig, gapminder[gapminder.continent == continent].lifeExp.median())
# add_figure_to_subplot() ?
我可以单独查看这些,但我想制作一个按顺序显示所有这些生成的数字的报告。如何制作这些图形对象的子图,或在子图跟踪中复制这些图?
解决方案
推荐阅读
- javascript - 如何使用鼠标滚轮和带有自定义导航的 MAC 触控板滑动 owl carousel 滑块和光滑滑块?
- machine-learning - 数据集不平衡,大小限制为 60mb,电子邮件分类
- java - 我无法将我的对象主体发送到有角度的两个输入字段中
- laravel - laravel 中的以下代码发送卖家(没有身份验证)邮件不起作用
- github - PyCharm 无法“从版本控制中签出”
- laravel-5 - 如何在 TDD 测试中运行 delete 方法?
- c# - 使我的 WinForms 应用程序在使用 Console.WriteLine() 时表现得像控制台应用程序一样
- python - 找不到 pip 包
- docker - 单节点 Kubernetes 集群上的 HPA 实现
- r - 使用officeR在闪亮中生成word报告