Replies: 2 comments 1 reply
-
Try this: from pyqtgraph import QtCore
def my_key_pressed(vb, ev):
if ev.key() == QtCore.Qt.Key.Key_Left:
vb.pan_x(steps=-1)
return True
elif ev.key() == QtCore.Qt.Key.Key_Right:
vb.pan_x(steps=+1)
return True
return orig_key_pressed(vb, ev)
orig_key_pressed = fplt._key_pressed
fplt._key_pressed = my_key_pressed |
Beta Was this translation helpful? Give feedback.
0 replies
-
Wow. Thanks a lot. Worked like a charm. The way I am planning to use is, I have some filters like the below:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am able to plot the OHLC chart for a stock from a local csv file. It displays the latest 300 candles since i have set it to display like this ax = fplt.create_plot('Example Plot', rows=1, init_zoom_periods=300). I would like to make it more interactive by giving a past date as a reference. For e.g if the past date is 6-June-2023, it should display 300 candles ending at 6-June-2023 and as I press the right arrow button, the entire plot should shift 1 bar to the left and display 300 candles ending on 7-june-2023 (the next trading date for which OHLCV data is available). Now if I press the left arrow, it should display the 300 candles ending again on 6-June-2023. The current code looks like this:
`import finplot as fplt
import pandas as pd
def calc_plot_data(df):
'''Returns data for all plots and for the price line.'''
price = df['open close high low'.split()]
volume = df['open close volume'.split()]
ma50 = ma200 = vema24 = None
ma50 = price.close.rolling(50).mean()
ma200 = price.close.rolling(200).mean()
vema24 = volume.volume.ewm(span=24).mean()
plot_data = dict(price=price, volume=volume, ma50=ma50, ma200=ma200, vema24=vema24)
return plot_data
plots = {}
fplt.y_pad = 0.07 # pad some extra (for control panel)
fplt.max_zoom_points = 7
fplt.autoviewrestore()
ax = fplt.create_plot('Example Plot', rows=1, init_zoom_periods=300)
axo = ax.overlay()
ax.set_visible(xaxis=True)
df=pd.read_csv("TESLA.csv")
df = df.astype({'date':'datetime64[ns]', 'open':float, 'high':float, 'low':float, 'close':float, 'volume':float})
df=df.set_index('date')
data = calc_plot_data(df)
plots['price'] = fplt.candlestick_ochl(data['price'], ax=ax)
plots['volume'] = fplt.volume_ocv(data['volume'], ax=axo)
fplt.show()
`
Beta Was this translation helpful? Give feedback.
All reactions