mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

Automatically make plot fullscreen

Open abdurrahmaan opened this issue 4 years ago • 7 comments

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

abdurrahmaan avatar Apr 08 '20 22:04 abdurrahmaan

Not yet. But we could easily add a kwarg to do that. Do you want to write the code for it?

DanielGoldfarb avatar Apr 08 '20 22:04 DanielGoldfarb

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?

abdurrahmaan avatar Apr 08 '20 23:04 abdurrahmaan

Certain I can guide you. Will have to wait till next week though.

DanielGoldfarb avatar Apr 08 '20 23:04 DanielGoldfarb

Is there a way to fullscreen?

tradingfran avatar Jul 12 '20 01:07 tradingfran

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()

DanielGoldfarb avatar Jul 12 '20 04:07 DanielGoldfarb

It would be great to be able to fullscreen by just setting an atribute = True.

Thank you!

tradingfran avatar Jul 12 '20 04:07 tradingfran

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.

DanielGoldfarb avatar Dec 16 '21 02:12 DanielGoldfarb