繁体   English   中英

将垂直线添加到 plotly 快递图表以显示最后的观察结果

[英]Add vertical line to plotly express charts to show last observations

使用这个教科书示例,任何人都可以建议您如何在每个图表中添加一条垂直线以显示最后的观察结果。 如果数字是恒定的,可以使用 fig.add_vline 但我需要它是动态的。

px.histogram(data_frame = diamonds,x= 'price',facet_col = 'cut')

非常感谢!

你的下一个问题给了我一个新的见解:在表达中,你说不能在多面图中绘制单独的垂直线,但我的立场是正确的。 我们获取钻石每个切工度数的数据,得到其最终价格,并将其指定为垂直线的值。 钻石数据取自 Seaborn 数据集。

import seaborn as sns
import plotly.express as px

diamonds = sns.load_dataset('diamonds')
fig = px.histogram(data_frame=diamonds, x='price', facet_col='cut')

for c,idx in zip(diamonds['cut'].unique(),[(1,1),(1,2),(1,3),(1,4),(1,5)]):
    df = diamonds[diamonds['cut'] == c]
    print(c, df['price'].tail(1).values[0])
    fig.add_vline(x=df['price'].tail(1).values[0], line_width=1, line_dash='solid', line_color='red', row=idx[0], col=idx[1])

fig.show()

Ideal 2757
Premium 2757
Good 2757
Very Good 2757
Fair 2747

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM