【发布时间】:2021-12-18 02:58:42
【问题描述】:
我正在绘制一系列与 1 月至 10 月范围内的月度测量值相关的值。我在这里发布了我的代码(尽管我无法共享数据框)。 所以,问题是这样的:正如你从picture 看到的那样,当我用鼠标悬停时,它会显示月份(在这种情况下是一月),这是正确的。但是通过查看 x 轴,看起来这些条形与 2 月相关联。所以基本上我需要“重新调整”。我尝试使用 x 轴的 nticks 参数,但如果我增加它开始显示我不需要的周数(例如,通过将 nticks = 35 它显示月份之间的中间日期数(例如,1 月 17 日写在 1 月和 2 月之间) ))。 有没有办法解决这个问题?提前致谢!
fig = go.Figure()
fig.update_layout(
title='Energia Consumata VS Energia Prelevata VS Energia Immessa VS Energia Autoconsumata VS Energia Prodotta',
xaxis_tickfont_size=14,
xaxis = dict(
showgrid =True,
zeroline = True,
nticks = 20,
showline = True,
title='Tempo',
titlefont_size=16,
tickfont_size=14,
),
yaxis=dict(
showgrid =True,
zeroline = True,
nticks = 20,
showline = True,
title='kWh',
titlefont_size=16,
tickfont_size=14,
),
barmode='group',
bargap=0, # gap between bars of adjacent location coordinates.
bargroupgap=0 # gap between bars of the same location coordinate.
)
#Totale fabbisogno della comunità
fig.add_trace(go.Bar(x=timeframe, y=df_comunita.Consumo,
base=0,
marker_color='red',
name='Energia Consumata Totale'
))
#Totale Prelevata dalla Rete
fig.add_trace(go.Bar(x=timeframe, y=df_comunita.Energia_Attiva_Ingresso_Delta,
base=0,
marker_color='#ff8000',
name='Energia Prelevata dalla Rete'
))
#Totale Prodotta
fig.add_trace(go.Bar(x=timeframe, y=df_comunita.Produzione_Impianti_Associati,
base=0,
marker_color='yellow',
name='Energia Prodotta'
))
#Totale Immessa in Rete
fig.add_trace(go.Bar(x=timeframe, y=df_comunita.Energia_Attiva_Uscita_Delta,
base=0,
marker_color='green',
name='Energia Immessa in Rete'
))
#Totale Autoconsumata
fig.add_trace(go.Bar(x=timeframe, y=df_comunita.Energia_Autoconsumata,
base=0,
marker_color='#2600ff',
name='Energia Autoconsumata'
))
#Consumo medio CER
fig.add_trace(go.Scatter(x=df_comunita.GG_ore_minuti, y = df_comunita['Consumo'],
line = dict(color = 'black', width=0.5),
name = "Consumo comunità"))
fig.update_xaxes(rangeslider_visible=True)
fig.show()
【问题讨论】: