python - How to determine screen size in matplotlib -


i looking way screen size in pixels using matplotlib interactive backend (e.g. tkagg, qt4agg, or macosx).

i trying write function can open window @ set of standard locations on screen e.g. right half of screen, or top-right corner.

i wrote working solution here, copied below, requires 1 use full_screen_toggle() (as suggested here) create full-screen window measure size.

i looking way screen size without creating full-screen window , changing size.

import matplotlib.pyplot plt  def move_figure(position="top-right"):     '''     move , resize window set of standard positions on screen.     possible positions are:     top, bottom, left, right, top-left, top-right, bottom-left, bottom-right     '''      mgr = plt.get_current_fig_manager()     mgr.full_screen_toggle()  # primitive works screen size     py = mgr.canvas.height()     px = mgr.canvas.width()      d = 10  # width of window border in pixels     if position == "top":         # x-top-left-corner, y-top-left-corner, x-width, y-width (in pixels)         mgr.window.setgeometry(d, 4*d, px - 2*d, py/2 - 4*d)     elif position == "bottom":         mgr.window.setgeometry(d, py/2 + 5*d, px - 2*d, py/2 - 4*d)     elif position == "left":         mgr.window.setgeometry(d, 4*d, px/2 - 2*d, py - 4*d)     elif position == "right":         mgr.window.setgeometry(px/2 + d, 4*d, px/2 - 2*d, py - 4*d)     elif position == "top-left":         mgr.window.setgeometry(d, 4*d, px/2 - 2*d, py/2 - 4*d)     elif position == "top-right":         mgr.window.setgeometry(px/2 + d, 4*d, px/2 - 2*d, py/2 - 4*d)     elif position == "bottom-left":         mgr.window.setgeometry(d, py/2 + 5*d, px/2 - 2*d, py/2 - 4*d)     elif position == "bottom-right":         mgr.window.setgeometry(px/2 + d, py/2 + 5*d, px/2 - 2*d, py/2 - 4*d)   if __name__ == '__main__':      # usage example move_figure()      plt.figure(1)     plt.plot([0, 1])     move_figure("top-right")      plt.figure(2)     plt.plot([0, 3])     move_figure("bottom-right") 

this works os x:

import appkit [(screen.frame().size.width, screen.frame().size.height) screen in appkit.nsscreen.screens()] 

the apple document on nsscreen class.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -