python画垂直于坐标轴的线,如何在Python API中使用plotly在x轴范围中间位置绘制一条垂直线?...

该博客探讨了如何在Python Plotly中动态地绘制垂直线,使其始终保持在x轴范围的中点位置。当数据过滤导致x轴范围变化时,线的位置会相应调整。示例代码展示了如何根据数据集的子集(如'Americas'和'Europe')更新垂直线的位置。
摘要由CSDN通过智能技术生成

I'm trying to plot a vertical line that's dynamically positioned so that when filtering happens, the line will move accordingly. For example, with the below code, I can plot a stationary vertical line at 25K which works with the full dataset as the median, but when the data is filtered to "Americas" only since the x-axis range is now 45K, the line is not at the median position anymore.

So how can I plot a vertical line that's positioned at the x-axis range's median position? Thanks

import pandas as pd

import plotly.graph_objs as go

from plotly.offline import init_notebook_mode, iplot

init_notebook_mode(connected=True)

df = pd.read_csv('https://raw.githubusercontent.com/yankev/test/master/life-expectancy-per-GDP-2007.csv')

americas = df[(df.continent=='Americas')]

europe = df[(df.continent=='Europe')]

trace_comp0 = go.Scatter(

x=americas.gdp_percap,

y=americas.life_exp,

mode='markers',

marker=dict(size=12,

line=dict(width=1),

color="navy"

),

name='Americas',

text=americas.country,

)

trace_comp1 = go.Scatter(

x=europe.gdp_percap,

y=europe.life_exp,

mode='markers',

marker=dict(size=12,

line=dict(widt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值