这是我的情节破折号:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import pandas as pd
data = pd.read_csv('https://raw.githubusercontent.com/AmirForooghi/stocks_csv/master/stocks_sample.csv')
df_1 = data.loc[data.sym == 'f']
df_2 = data.loc[data.sym == 'i']
df_3 = data.loc[data.sym == 'c']
fig = make_subplots(rows=2, cols=3, row_heights=[0.8, 0.2], vertical_spacing=0,
horizontal_spacing=0.05, shared_xaxes=True, shared_yaxes=False)
fig.add_trace(go.Candlestick(open=df_1['open'], high=df_1['high'], low=df_1['low'],
close=df_1['close'],
increasing_line_color='#0384fc', decreasing_line_color='#e8482c'
), row=1, col=1)
fig.add_trace(go.Scatter(x=list(range(40)), y=df_1['pct'], line_color='#fae823', hovertemplate=[]),
row=2, col=1)
fig.add_trace(go.Candlestick(open=df_2['open'], high=df_2['high'], low=df_2['low'],
close=df_2['close'],
increasing_line_color='#0384fc', decreasing_line_color='#e8482c'
), row=1, col=2)
fig.add_trace(go.Scatter(x=list(range(40)), y=df_2['pct'], line_color='#fae823', hovertemplate=[]),
row=2, col=2)
fig.add_trace(go.Candlestick(open=df_3['open'], high=df_3['high'], low=df_3['low'],
close=df_3['close'],
increasing_line_color='#0384fc', decreasing_line_color='#e8482c'
), row=1, col=3)
fig.add_trace(go.Scatter(x=list(range(40)), y=df_3['pct'], line_color='#fae823', hovertemplate=[]),
row=2, col=3)
fig.update_layout({'plot_bgcolor': "#21201f", 'paper_bgcolor': "#21201f", 'legend_orientation': "h"},
legend=dict(y=1, x=0),
font=dict(color='#dedddc'), dragmode='pan', hovermode='x unified', showlegend=False,
margin=dict(b=20, t=0, l=0, r=40))
fig.update_xaxes(showgrid=False, zeroline=False, rangeslider_visible=False, showticklabels=False, showline=True,
linecolor='#969799', showspikes=True, spikemode='across', spikesnap='data',
spikedash='dash', spikecolor='#ebeae8', spikethickness=0.5)
fig.update_yaxes(showgrid=False, zeroline=False, showticklabels=True, showline=False)
fig.update_traces(hoverinfo='skip', xaxis='x1', col=1)
fig.update_traces(hoverinfo='skip', xaxis='x2', col=2)
fig.update_traces(hoverinfo='skip', xaxis='x3', col=3)
app = dash.Dash(__name__)
app.layout = html.Div(children=[
dcc.Graph(figure=fig, id='chart', config={'displayModeBar': False}),
])
if __name__ == '__main__':
app.run_server(debug=True, dev_tools_ui=False, dev_tools_props_check=False)
我对此图的问题是,y轴的刻度标签不正确。如您所见,对于第二和第三列,它已被删除,对于第一列,它是重叠的。我尝试了这种solution的方法,但是如果我删除了这些fig.update_traces
,则尖峰将改变(有关更多信息,请参见下面的更新1)。我所说的尖峰如下所示:可以看到,当光标位于散点图上时,它将在整个列上绘制一条线。
我想像现在这样完全保持这些峰值。我现在如何解决壁虱标签问题?
UPDATE 1:
如果我在代码末尾删除三个fig.update_traces
,则会出现尖峰,但它们不是我想要的。这两个屏幕截图对此进行了说明。第一个是我想要的峰值,第二个是没有fig.update_traces
的峰值:
主要区别在于,上图中的尖峰遍布整列,仅在光标位于散点图上时才出现。我需要这种方式。它不是为了更好的外观!它们应保持与上图完全相同。