Plotly 中的浮动棒图

Floating stick graph in Plotly

如何使用 Plotly 生成这种类型的 'floating stick'(或 'high/low'?)图表?我浏览了这些示例,但找不到完全相同的东西 - 最重要的是设置 bars/sticks 不从零开始。

请注意,线条不是误差线。

制作棒图的一种方法是在 asymmetric error bars that have zero width 上使用负偏移。这是一个例子:

import plotly.plotly as py
from plotly.graph_objs import ErrorY, Scatter

x = [1, 2, 3, 4]
y = [4, 7, 5, 9]
stick_top = [10, 6, 7, 11]
stick_bottom = [6, 4, 3, 4]

error_bar_positive_offset = [si - yi for (yi, si) in zip(y, stick_top)]
error_bar_negative_offset = [yi - si for (yi, si) in zip(y, stick_bottom)]

py.plot([
    Scatter(x=x, y=y, mode='markers',
        error_y=ErrorY(
            symmetric=False, 
            array=error_bar_positive_offset, 
            arrayminus=error_bar_negative_offset,
            width=0
        )
    )], filename='stick-chart')

https://plot.ly/~chris/15416

为了防止这个问题再次与某人相关,我应该强调 plotly 现在有一种创建烛台图表的方法:https://plotly.com/python/candlestick-charts/

例如:

import plotly.graph_objects as go
import pandas as pd

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

fig = go.Figure(data=[go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'], high=df['AAPL.High'],
                low=df['AAPL.Low'], close=df['AAPL.Close'])
                     ])

fig.update_layout(xaxis_rangeslider_visible=False)
fig.show()