简体   繁体   中英

Hide hover data on candlestick charts in python plotly

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. 在此处输入图像描述

This is my entire code:

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

And for dash:

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)

Solution:

hoverinfo='skip'

Plot:

在此处输入图像描述

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

在此处输入图像描述

Code:

# 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM