Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i show plot on tkinter #178

Closed
xiaofeng68 opened this issue Jun 18, 2020 · 1 comment
Closed

how can i show plot on tkinter #178

xiaofeng68 opened this issue Jun 18, 2020 · 1 comment
Labels
question Further information is requested

Comments

@xiaofeng68
Copy link

how can i show plot on tkinter.

    daily = LocalData.getInstance().data('000001',0)
    daily['Date'] = pd.to_datetime(daily['trade_date'])
    daily['Open'] = daily['close']
    daily['High'] = daily['high']
    daily['Low'] = daily['low']
    daily['Close'] = daily['close']
    daily.set_index(["Date"], inplace=True)
    daily.index.name = 'Date'
    mpf.plot(daily)
@xiaofeng68 xiaofeng68 added the question Further information is requested label Jun 18, 2020
@DanielGoldfarb
Copy link
Collaborator

I am not familiar with TkInter, but I can show you what I have seen here in these discussions.
There appear to be two approaches:

  1. Use mpf.plot(data,...,returnfig=True) to return the Figure and Axes, and use that Figure in TkInter. An example of this approach can be found here: how to embed mplfinance to certain program in python? #125 (comment) You can also see another example here.

  2. Use mpf.plot(data,...,savefig=buffer) to save the figure image into an io.BytesIO buffer, and then pass that buffer to TkInter. An example of this approach can be found here: Bug Report: mplfinance >= 0.12.5a0 crashes without an error when loading an plot image in tKinter #170 (comment) (Please note: although that comment discusses a bug, the example code is valid and the bug only occurs if you use matplotlib's "TkAgg" bakcend. But if you use any other matplotlib backend, it should work). See also this comment here.

I hope the above reference help you to find what you are looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants