mplfinance
mplfinance copied to clipboard
Automatically make plot fullscreen
Hi,
I'm very new to mplfinance and an amateur with Python
This package is awesome, thank you for your work. I was just wondering if there is a way to make the plot automatically appear in fullscreen? Currently it appears as a window and you have to enlarge it manually...
I know that in Matplotlib it can be done using:
plt.get_current_fig_manager().window.state('zoomed')
Is there a way to do it with mplfinance?
Thank you
Not yet. But we could easily add a kwarg to do that. Do you want to write the code for it?
I've never done anything like that before but I'd love to have a go at it. Can you provide me with some guidance please?
Certain I can guide you. Will have to wait till next week though.
Is there a way to fullscreen?
This should be relatively easy to code, but according to this answer the code may have to check which backend the user is running.
I tested with backend Qt5Agg and plt.get_current_fig_manager().window.showMaximized()
worked fine. Let me know if you are interested in writing the code for mplfinance to support kwarg fullscreen=True
.
Alternatively, you can do this now with the following workaround: Set returnfig=True
when calling mpf.plot()
Then add the appropriate lines of code from this answer, and call plt.show(), for example:
import mplfinance as mpf
import matplotlib.pyplot as plt
...
mpf.plot(df,...,returnfig=True)
fm = plt.get_current_fig_manager()
fm.window.showMaximized()
plt.show()
It would be great to be able to fullscreen by just setting an atribute = True.
Thank you!
DId some playing around in plotting.py
but could not quite get this to work in all cases:
783 elif not config['returnfig']:
784 if config['fullscreen']:
785 figmgr = plt.get_current_fig_manager()
786 bkend = plt.get_backend()
787 if bkend == 'TkAgg':
788 #figmgr.window.state('zoomed')
789 figmgr.resize(*figmgr.window.maxsize())
790 elif bkend == 'wxAgg':
791 figmgr.frame.Maximize(True)
792 else: # Qt4Agg, Qt5Agg, maybe others??
793 figmgr.window.showMaximized()
794 plt.show(block=config['block']) # https://stackoverflow.com/a/13361748/1639359
795 if config['closefig'] == True or (config['block'] and config['closefig']):
796 plt.close(fig)
not sure whether i want to put code in mplfinance that will strongly depend on the users choice for matplotlib backend, and not be certain that I have all backends working in all operating systems (for example, supposedly figmgr.window.state('zoomed')
works on windows but have to use figmgr.resize(*figmgr.window.maxsize())
on ubuntu).
Will leave this issue open for now to see if we can come up with a clean way to do this.