在python中以图形方式在烛台图表上隐藏悬停数据

在python中以图形方式在烛台图表上隐藏悬停数据

本文介绍了在python中以图形方式在烛台图表上隐藏悬停数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用go.Candlestick创建了一个简单的烛台图.当我在烛台图表上悬停时,我想隐藏数据.我设置了hoverinfo='none',但是它仍然在悬停时显示一个图标,如下面的屏幕截图所示.我怎么藏起来?我的整个代码都在图片下方.

I created a simple candlestick chart using go.Candlestick. I want to hide data when I hover the candlestick chart. I set hoverinfo='none' but it still shows an icon on hovering like the screenshot below. How can I hide it? My entire code is below the image.

这是我的完整代码:

def online_chart_1(sym_1):
    data_for_chart = pd.read_csv('C:\\Users\\AF\\Desktop\\python\\results\\csv\\data_for_chart.csv')
    historical_ha_vo = pd.read_csv('C:\\Users\\AF\\Desktop\\python\\results\\csv\\historical_ha_vo.csv')

    historical_ha_vo = historical_ha_vo.loc[historical_ha_vo.sym == sym_1].tail(59)
    data_for_chart = data_for_chart.loc[data_for_chart.sym == sym_1]
    df_appended = historical_ha_vo.append(data_for_chart, ignore_index=True)

    fig = make_subplots(rows=2, cols=1, row_heights=[0.8, 0.2], vertical_spacing=0)
    fig.add_trace(go.Candlestick(open=df_appended['o'], high=df_appended['h'], low=df_appended['l'],
                                 close=df_appended['c'],
                                 increasing_line_color='#0384fc', decreasing_line_color='#e8482c', name=sym_1,
                                 hoverinfo='none',
                                 ), row=1, col=1)

    fig.add_trace(go.Scatter(y=df_appended['vo'], marker_color='#fae823', name='VO', hovertemplate=[]), row=2, col=1)
    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',
                      margin=dict(b=20, t=0, l=0, r=40))

    fig.update_xaxes(showgrid=False, zeroline=False, rangeslider_visible=False, showticklabels=False,
                     showspikes=True, spikemode='across', spikesnap='data', showline=False, spikedash='solid'
                     )
    fig.update_yaxes(showgrid=False, zeroline=False)
    fig.update_traces(xaxis='x')

    return fig

还有破折号:

app = dash.Dash(__name__)

app.layout = html.Div([html.Div(dcc.Graph(id='chart', figure=online_chart_1('zob'),
                                          config={'displayModeBar': False}))])


if __name__ == '__main__':
    app.run_server(debug=True, dev_tools_ui=False, dev_tools_props_check=False)

推荐答案

解决方案:

hoverinfo='skip'

情节:

没有hoverinfo='skip',下面的相同代码段将为您提供:

Without hoverinfo='skip' the same code snippet below will give you this:

代码:

# imports
import plotly.graph_objects as go

import pandas as pd
from datetime import datetime

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'], hoverinfo='skip')])

fig.show()

这篇关于在python中以图形方式在烛台图表上隐藏悬停数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:15