如何使用绘图中的范围分隔符?

oll*_*lli 6 python plotly

我想使用plotly从某些图中的x轴中删除某些间隔。我从https://plotly.com/python/time-series/找到了附加的示例。但运行它给了我错误

ValueError:为plotly.graph_objs.layout.XAxis类型的对象指定无效属性:'rangebreaks'

我什至升级了我的情节版本。如何使用 rangebreaks 属性?

import plotly.express as px
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = px.scatter(df, x='Date', y='AAPL.High', range_x=['2015-12-01', '2016-01-15'],
                 title="Hide Gaps with rangebreaks")
fig.update_xaxes(
    rangebreaks=[
        dict(bounds=["sat", "mon"]), #hide weekends
        dict(values=["2015-12-25", "2016-01-01"])  # hide Christmas and New Year's
    ]
)
fig.show()
Run Code Online (Sandbox Code Playgroud)

ric*_*hao 0

如果你正在运行最新版本的plotly,这应该可以工作,也许尝试重新启动内核

并检查系统中是否有这些文件: ...\Lib\site-packages\plotly\validators\layout\yaxis_rangebreaks.py ..\Lib\site-packages\plotly\validators\layout\xaxis_rangebreaks.py