Home > Software design >  Missing part of the data in graph
Missing part of the data in graph

Time:07-10

I'm writing a program which will show the candlestick chart of Gold and detect patterns. I'm getting the data from yfinance and trying to draw the chart with plotly, but I see that some parts of the data are missing. I checked the data with mplfinance and everything worked successfully, but I need it in plotly.

import plotly.graph_objects as go
import pandas as pd
import yfinance as yf
import talib

import mplfinance as mpf



data = yf.download(tickers="GC=F", period="5d", interval="5m")
fig = go.Figure(data=[go.Candlestick(x=data.index,
            open=data['Open'], high=data['High'],
            low=data['Low'], close=data['Close'])
                 ])

fig.update_layout(xaxis_rangeslider_visible=False)
fig.write_html('first_figure.html', auto_open=True)

CodePudding user response:

There are indeed some lacunae in the original yahoo data (the website has inconsistent X axis rather than showing gaps). For the purpose of time series analysis, applying data = data.resample('5T').ffill() (or interpolate()) is about the best you can do I presume.

If you wish to imitate yahoo chart behaviour, you'll have to configure rangebreaks like in enter image description here

  • Related