Can't see new updated candles
Requirements (place an x in each of the [ ])**
- [x ] I realize finplot is not a web lib. (Hint: it's native!)
- [ x] I've read the snippets and not found what I'm looking for.
- [ x] I've searched for any related issues and avoided creating a duplicate issue.
- [ x] I've updated finplot (
pip install -U finplot). - [ x] I've supplied the required data to run my code below.
Code to reproduce
import os
from time import sleep
import pandas as pd
import finplot as fplt
from PyQt6.QtWidgets import QGridLayout, QGroupBox, QLabel, QLineEdit, QPushButton, QHBoxLayout, QSizePolicy, QDialog, QVBoxLayout, QMessageBox, QCheckBox, QSpacerItem, QWidget
from PyQt6.QtCore import Qt
import numpy as np
def start(self):
w = fplt.foreground = '#eef'
b = fplt.background = fplt.odd_plot_background = '#434651'
fplt.candle_bull_color = fplt.volume_bull_color = fplt.candle_bull_body_color = fplt.volume_bull_body_color = '#0c3299'
fplt.candle_bear_body_color = "#f23645"
fplt.candle_bull_color = '#000000'
fplt.candle_bear_color = '#000000'
fplt.volume_bear_color = '#000000'
# add text to the right and bottom
self.ax = fplt.create_plot('Vyper', maximize=True, rows=1) # was 2
self.ax.getAxis('right').style['showValues'] = True
# self.ax.getAxis('bottom').style['showValues'] = True
self.ax.setLabel('right', 'Price (USD)')
# self.ax.setLabel('bottom', 'Time')
# self.ax.vb.win.scene().sigMouseClicked.connect(self.on_mouse_clicked)
self.hover_label = fplt.add_legend('', ax=self.ax)
self.axo = self.ax.overlay()
fplt.set_time_inspector(self.update_legend_text,
ax=self.ax, when='hover')
fplt.add_crosshair_info(self.update_crosshair_text, ax=self.ax)
self.plot_candles, self.plot_volume, self.plot_td_up, self.plot_td_dn = fplt.live(
4)
self.run()
self.create_chart()
def run(self):
with open('data.csv', 'r') as f:
self.df = pd.read_csv(f)
self.df['date'] = pd.to_datetime(self.df['date'], errors='coerce')
self.df['date'] = self.df['date'].astype('int64')
self.df.reset_index(inplace=True)
self.df.rename(columns={'index': 'Unnamed: 0'}, inplace=True)
fplt.candlestick_ochl(
self.df[['date', 'open', 'close', 'high', 'low']], ax=self.ax)
def create_chart(self):
fplt.lod_labels = 200
fplt.autoviewrestore()
fplt.timer_callback(self.run, 5.0)
fplt.show()
Describe the bug
I am trying to read from a file that is being updated every 5 seconds, And inside the ui i just see new timestamps and empty candles being created for some reason
Screenshots
https://github.com/highfestiva/finplot/assets/43996999/1c545905-60ee-4724-9bc4-c12e1ea6a27d
As you can see from the video at the bottom a new timestamps has being created but I can't see the candle
Reproducible in:
OS: Mac OS finplot version: 1.9.2 pyqtgraph version: 0.13.3 pyqt version: PyQt6
Please look in the examples for how to live update the chart. For instance examples/complicated.py should contain what you're looking for.
Thanks it worked!
Also, I have this code that creates labels but for some reason it wont show on the live candles it messes things up
def add_hh_ll_hl_lh_labels(self):
# Create new charts, filtering the HH HL LH LL columns and adding the labels
HH_LH_rows = [{'date': row['date'], 'high': row['high'], 'HH HL LH LL': row['HH HL LH LL'] + f' {index}'}
for index, row in self.df.iterrows() if row['HH HL LH LL'] in ('HH', 'LH')]
HL_LL_rows = [{'date': row['date'], 'low': row['low'], 'HH HL LH LL': row['HH HL LH LL'] + f' {index}'}
for index, row in self.df.iterrows() if row['HH HL LH LL'] in ('HL', 'LL')]
self.td_up_labels = pd.DataFrame(HH_LH_rows)
self.td_dn_labels = pd.DataFrame(HL_LL_rows)
if not self.td_up_labels.empty:
self.plot_td_up.labels(self.td_up_labels, color='#00FF00')
if not self.td_dn_labels.empty:
self.plot_td_dn.labels(self.td_dn_labels, color='#FF0000', anchor=(0.5, 0))
And this is my update function which will be called back:
def update(self):
with open('data.csv', 'r') as f:
self.df = pd.read_csv(f)
self.df['date'] = pd.to_datetime(self.df['date'], errors='coerce')
self.df['date'] = self.df['date'].astype('int64')
self.df.reset_index(inplace=True)
self.df.rename(columns={'index': 'Unnamed: 0'}, inplace=True)
self.plot_candles.candlestick_ochl(
self.df[['date', 'open', 'close', 'high', 'low']])
self.add_hh_ll_hl_lh_labels()
See the bfx.py example. It does exactly what you're asking for.