1

I can create very nice figures with

import matplotlib.pyplot as plt
fig = plt.figure()

often, I need to generate large figures and I do

fig = plt.figure(figsize=(80,60))

which is fine, but generates figures that are larger than the screen and need to be manually resized. This is desired behavior, if I read the documentation I see:

figsize
w,h tuple in inches

So I have found the sizes of my screen manually, and now it generate nice fullscreen figures. However, if I change monitor I need to repat this. How do I find programmtatically the size of the screen in use?

I have found many answers, but they all rely on external libraries or are platform-specific, or back-end specific Any solution that I could trasparently use across OS, backends, without adding dependencies to my project?

How to determine screen size in matplotlib.

I have tried

window = plt.get_current_fig_manager().window
screen_x, screen_y = window.wm_maxsize()

but I am seeing the following exception:

AttributeError: 'MainWindow' object has no attribute 'wm_maxsize'

I am using Python 2.7 within Anaconda on Linux, Win 7+ with a automatic graphic backend.


UPDATE

It seems that many ways exist

https://www.blog.pythonlibrary.org/2015/08/18/getting-your-screen-resolution-with-python/

How do I get monitor resolution in Python?

https://stackoverflow.com/a/42355364/2666859

However, none of them is platform or backend independent. Perhaps an alternative is first detect platform and then the backend in use and cascade in a long multicase if with all the particular solutions as cases? Apparently, such a chain solution exists https://stackoverflow.com/a/21213145/4124317

Is this pythonic?Is the best way to go?

00__00__00
  • 4,834
  • 9
  • 41
  • 89
  • 2
    try this answer: https://stackoverflow.com/a/42355364/2666859 – Serenity Oct 23 '17 at 11:44
  • Works on the window installation. Later I will try it on Linux. However, I think this is not the complete answer as it says ''depend on your matplotlib backend. For Qt'' – 00__00__00 Oct 23 '17 at 11:46
  • So I was wondering if the screen size could be access by other libs, such as os/sys – 00__00__00 Oct 23 '17 at 11:46
  • 1
    See [this blog](https://www.blog.pythonlibrary.org/2015/08/18/getting-your-screen-resolution-with-python/) , and also [this](https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python) answer – DavidG Oct 23 '17 at 11:49
  • Thanks. The blog post presents only external libraries/platform dependant solutions – 00__00__00 Oct 23 '17 at 11:51
  • same applies to the other SO request – 00__00__00 Oct 23 '17 at 11:53
  • I am adding the links you shared with me to the question – 00__00__00 Oct 23 '17 at 11:53
  • Even if there was a system independent way of finding out the screen size in python, you would not find it by asking about matplotlib plots. There is already [an answer which implements a chain of solutions](https://stackoverflow.com/a/21213145/4124317) and is hence pretty system independent. What else are you expecting to see? – ImportanceOfBeingErnest Oct 23 '17 at 12:13
  • maybe an undocumented internal function of matplotlib which could do this? matplotlib must get the screen size somewhere, and I would like to follow that pathway – 00__00__00 Oct 23 '17 at 12:16
  • I guess there is no universal solution according to very different backends and OS – Serenity Oct 23 '17 at 12:19
  • Why do you think that "matplotlib must get the screen size somewhere"? This is exactly the purpose of a backend. So yes, each matplotlib backend will be able to determine the screen size or let it be determined by some method (e.g. `showMaximized()` for Qt). – ImportanceOfBeingErnest Oct 23 '17 at 12:24
  • ok, I was hoping that somewhere, matplotlib would wrap these calls to back-end specific implementations into a showMaximized() – 00__00__00 Oct 23 '17 at 12:27
  • Basically avoiding to rewrite this chain solution https://stackoverflow.com/a/21213145/4124317 – 00__00__00 Oct 23 '17 at 12:28
  • It is still sounds pretty legit to me as a question. If I need to include the chain of solutions proposed, the largest part of the script will be devoted to open a figure full screen, which is something can be done easily in many languages – 00__00__00 Oct 23 '17 at 12:29
  • Yes, but those languages clearly define a system to be used. So, once you define the system to be used, this can easily done in two lines of code. – ImportanceOfBeingErnest Oct 23 '17 at 13:23

0 Answers0