Python Plotly:两行子图中的标签问题

Python Plotly:两行子图中的标签问题,python,plotly,plotly-dash,Python,Plotly,Plotly Dash,这是我的绘图破折号代码: 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.githubusercont

这是我的绘图破折号代码:

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轴的标签不正确。 如您所见,对于第二列和第三列,它被删除,而对于第一列,它是重叠的。 我尝试了这种方法,但如果我删除那些
fig.update\u跟踪
出现的峰值将发生变化(有关更多信息,请参阅下面的更新1)。我所说的尖峰,如下图所示: 当光标位于散点图上时可以看到,它在整个列上绘制了一条线

我想让这些钉子保持现在的样子。我现在如何解决这个问题

更新1:

如果我删除代码末尾的三个
fig.update_跟踪
,则会出现尖峰,但它们不是我想要的。这两个屏幕截图说明了这一点。第一个是我的原始代码中的尖峰,第二个是没有
的尖峰。更新\u跟踪

主要区别在于上图中的尖峰贯穿整个列,仅当光标位于散点图上时才出现。我需要这样。这不是为了好看!他们应该保持与上图完全相同。

这是一个正在进行的答案

我删除了:

 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)
我得到的是尖峰,你可以看到你的gif:


我错过了什么?

你真正的目标是在没有悬停信息的情况下,在悬停时获得十字架吗?但这一次是针对多个子图?如果是这样,那么“如何对多个烛台图形应用十字光标”才是真正的问题。而这些标签实际上只是实现这一目标的副作用。@Vesland我已经“为多个烛台应用了十字线”。如果您运行我的代码,您可以看到,对于所有三列,crosshair都可以正常工作。我认为真正的问题是修复标签问题,同时保持十字线的风格,我想要的。十字线不再是问题了。我们用你99%的帮助解决了这个问题:)我明白了。。。这让我很困惑,因为你的代码片段只产生了一条垂直的而不是水平的尖峰线。“我再看看。”维斯特兰,我明白了。我想要这种样式的三列图表。