Closed sunjar2020 closed 1 year ago
Those are generic programming questions that are too broad to answer here (has nothing to do with finplot itself).
Sorry to bother you with some basic problems, I have solved these two problems after two hours of hard work. But could you please answer another little question? I think it has something with finplot.
That is, how to update the legend? My code is as follows. I don't know how to update the legend on subplot, the stock_list[i][0:6] is string type, it has changed over the course of the program. In my code's two way(Commented out and uncommented), the legend not update.
if not plots:
plots.append(fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']]))
plots.append(fplt.volume_ocv(df[['Open','Close','Volume']], ax = ax2)) #subplot 2, second axes
plots.append(fplt.plot(df['Flag'], color='#000000', ax = ax3, legend = 'StockCode '+ stock_list[i][0:6]))
#plots.append(fplt.add_legend(stock_list[i][0:6], ax = ax3))
else:
plots[0].update_data(df[['Open', 'Close', 'High', 'Low']])
plots[1].update_data(df[['Open','Close','Volume']])
plots[2].update_data(df[['Open','Close','Flag']])
#plots[2].update_date(fplt.add_legend(stock_list[i][0:6]))
See examples/snp500.py
.
I've recently been writing a program that displays stock prices in turn using the finplot library, and now it basically works, it reads all the filenames from the data directory and calls finplot in a loop to display candlestick and volume and stuff. But there are still two problems:
When the program starts to display the first stock, if I close the current window, it will display the next one, which is correct. But when I use the "key_pressed(vb, ev)" method, I want the program will update dataframe content when I press "right arrow" key, it doesn't work, because I don't know how to pass the parameter into the "key_pressed" function, if I write like this:
fplt.timer_callback(update(code))
It will prompt me that "code" is undefined.At present, the program can only display one main chart(candlestick). If I want to add more sub-charts, such as ax2, ax3, how should I add codes? I commented out two lines of code, and they don't work if I uncomment them, because I don't know the correct format to write them. If I add ax = ax2 directly after the commented code, it will prompt me that ax2 is not defined. Even if I add "global ax2" to the update function, it won't work. I refer to the example of bfx.py in the sample folder, but I can't find the corresponding method?
Could you take a look at these two issues when you're not busy? thank you very much.
here is all file( including code and sample datas): https://xfl.jp/5mYPAb
Here is my code: