我需要帮助,我试图弄清楚为什么我在 mplfinance 中选择的样式在我将其绘制到 tkinter 画布图时不起作用。
这是我的代码:
from tkinter import *
import datetime as dt
import yfinance as yf
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
import mplfinance as mpf
gui = Tk()
gui.geometry("800x700")
stock = 'SPY'
end = dt.datetime.now()
start = end - dt.timedelta(days=6)
df = yf.download(stock.upper(), start, end, interval = '5m')
def Plot_data(type='candle', grid= '-', style='nightclouds'):
fig = plt.Figure(figsize=(7,5), dpi=100)
chart = fig.add_subplot(111)
chart_canvas = FigureCanvasTkAgg(fig, master=gui)
chart_canvas.get_tk_widget().place(relx = .05, rely=.25)
s = mpf.make_mpf_style(base_mpf_style=style, gridstyle=grid)
mpf.plot(df, ax= chart, type = type, style = s)
Plot_data()
mainloop()
#Plotting it without tkinter and without the lines "" fig = plt.Figure()/
#chart = fig.add_subplot(111)"" works just fine,
#this is the customization I want in the tkinter window. Thank you.
def Plot_data(type='candle', grid= '', style='nightclouds'):
s = mpf.make_mpf_style(base_mpf_style=style, gridstyle=grid)
mpf.plot(df, type = type, style = s)
Plot_data()```