-
Notifications
You must be signed in to change notification settings - Fork 657
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
Hiding figure popup window when using Tkinter #304
Comments
I am not very familiar with using tkinter. In theory, because you have specified Perhaps someone with more experience using matplotlib with tkinter (for example @tacaswell or someone else within the @matplotlib/community) will have some insights into what is causing the Figure 1 window to be drawn. For me to try to determine what's going on, I would need to see all of your code. For example, where does |
Just to clarify "to see all of your code" ... I don't really need all of it, but I do need a complete set of code to minimally reproduce the issue if you would like me to look into it. |
Thanks. I am able to run it, but when I click plot I get just the one plot (not the extra "Figure 1" window). Perhaps later tonight when I have a little more time I will try running it on some of my other systems. This worked fine (no extra window) on WSL2 Ubuntu. I also have a separate Ubuntu boot (not under WSL), a Mac, and a Red Hat that I can try. Btw, what is your environment? Regarding the Therefore Mplfinance implements its own fig, ax = mpf.plot(chartData,type='candle',
style = s,
tight_layout=True,
title = "Test Plot",
figratio=(12,6),
figscale=0.50,
scale_padding=dict(bottom=1.75),
returnfig=True
) You can read more about HTH |
Thanks so much for the feedback on the scaling issue! I had a weird feeling that this might be a system or user setting error. Guess we haven’t fully confirmed this. I am running Windows 10 with Spyder IDE. I did reset all preferences back to default and I still get the second figure window. |
I installed python on Windows 10. I took the above test script, write it to disk using notepad, and then from powershell I ran python on that script (I did not install Spyder). I got the same result as when I ran it on Ubuntu: no second window. Everything seems normal. Will have to try to involve someone who is more expert than I am with matplotlib backends and GUIs who may have a clue here. Obviously something environmental, but I have no idea where to even begin. @KohliBuilt perhaps try that: Save the test script to a file and run it under PowerShell or CommandPrompt. Then depending on whether you still see the issue you will know whether it's a windows envinroment thing, or a Spyder environment thing. |
OK. I installed Spyder and ran it from inside Spyder and indeed I am able to reproduce the problem. This is clearly something specific to Spyder. We had another issue a while back that was also specific to Spyder and while it is unlikely this is related to that, it may be worth noting that Spyder runs Ipython in pylab mode which may treat things differently. For example, in that case it was found that None was treated as False in pylab mode but as True in all other environments (or perhaps "treated as" is the wrong expression; perhaps there was a different "default" boolean value that was used when the variable in question was of NoneType). At any rate, this is clearly Spyder related. The question is now whether we can isolate the cause and possibly patch mplfinance so that it will behave the same in Spyder as in other environments. |
Adding the following to your script fixes the issue in Spyder: import matplotlib.pyplot as plt
plt.ioff() reference: https://stackoverflow.com/a/53217287/1639359 |
It worked!!! @DanielGoldfarb you are amazing and I greatly appreciate all your time and support!! |
Glad it worked! |
@DanielGoldfarb I don't think the solution presented has fully resolved our issue. I noticed that when I close the GUI window the script continues running...which leads me to believe there is still some open window or figure that is hidden. For some reason it is not being destroyed when I close the main GUI window. Maybe there is a way to close it? For now I am running fig, ax = mpf.plot(chartData,type='candle',
style = s,
tight_layout=True,
title = "Test Plot",
figratio=(12,6),
figscale=0.50,
returnfig=True
)
plt.close(fig) |
I'm really not sure what I am doing with Spyder and tkinter, since I haven't really used them before; but with a little googling and some reasoning I was able to get it working. First let me describe what I am doing and what I saw. I am running your test program as a .py file on the left side of the Spyder interface. When I click the green triangle ("Run File") the window pops up with a button that says "Plot!". At the same time, in the IPython console I see In [1] runfile('C:/Users/dgold/issue304.py', wdir='C:/Users/dgold') I then click the "Plot!" button and the candlestick plot appears in the window. If I then click the "X" in the upper right hand corner, the window closes, but I do NOT see The main reason for the above description is just to make sure we are running things more-or-less the same way. I don't know how you got it working at all with
def on_closing():
plt.close('all')
window.destroy()
That seems to have done the trick. Let me know. |
First off, I love mplfinance and thanks for all your work!
I just started putting together a GUI to help me quickly review financial charts. I keep getting the figure window in addition to the plot being embedded in the GUI, as you can see below. Is there anyway to prevent the Figure 1 window from being presented?
Parts of my code:
The text was updated successfully, but these errors were encountered: