Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5512a2

Browse files
committed
Describe FigureManager
1 parent e285dde commit f5512a2

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,20 +2446,53 @@ def button_press_handler(event, canvas, toolbar=None):
24462446

24472447

24482448
class NonGuiException(Exception):
2449+
"""Raised when trying show a figure in a non-GUI backend."""
24492450
pass
24502451

24512452

24522453
class FigureManagerBase(object):
24532454
"""
2454-
Helper class for pyplot mode, wraps everything up into a neat bundle
2455+
A backend-independent abstraction of a figure container and controller.
2456+
2457+
The figure manager is used by pyplot to interact with the window in a
2458+
backend-independent way. It's an adapter for the real (GUI) framework that
2459+
represents the visual figure on screen.
2460+
2461+
GUI backends define from this class to translate common operations such
2462+
as *show* or *resize* to the GUI-specific code. Non-GUI backends do not
2463+
support these operations an can just use the base class.
2464+
2465+
This following basic operations are accessible:
2466+
2467+
**Window operations**
2468+
2469+
- `~.FigureManagerBase.show`
2470+
- `~.FigureManagerBase.destroy`
2471+
- `~.FigureManagerBase.full_screen_toggle`
2472+
- `~.FigureManagerBase.resize`
2473+
- `~.FigureManagerBase.get_window_title`
2474+
- `~.FigureManagerBase.set_window_title`
2475+
2476+
**Key and mouse button press handling**
2477+
2478+
The figure manager sets up default key and mouse button press handling by
2479+
hooking up the `.key_press_handler` to the matplotlib event system. This
2480+
ensures the same shortcuts and mouse actions across backends.
2481+
2482+
**Other operations**
2483+
2484+
Subclasses will have additional attributes and functions to access
2485+
additional functionality. This is of course backend-specific. For example,
2486+
most GUI backends have ``window`` and ``toolbar`` attributes that give
2487+
access to the native GUI widgets of the respective framework.
24552488
24562489
Attributes
24572490
----------
24582491
canvas : :class:`FigureCanvasBase`
2459-
The backend-specific canvas instance
2492+
The backend-specific canvas instance.
24602493
24612494
num : int or str
2462-
The figure number
2495+
The figure number.
24632496
24642497
key_press_handler_id : int
24652498
The default key handler cid, when using the toolmanager.
@@ -2474,7 +2507,6 @@ class FigureManagerBase(object):
24742507
24752508
figure.canvas.mpl_disconnect(
24762509
figure.canvas.manager.button_press_handler_id)
2477-
24782510
"""
24792511
def __init__(self, canvas, num):
24802512
self.canvas = canvas
@@ -2516,20 +2548,18 @@ def full_screen_toggle(self):
25162548
pass
25172549

25182550
def resize(self, w, h):
2519-
""""For GUI backends, resize the window (in pixels)."""
2551+
"""For GUI backends, resize the window (in pixels)."""
25202552

25212553
def key_press(self, event):
25222554
"""
25232555
Implement the default mpl key bindings defined at
2524-
:ref:`key-event-handling`
2556+
:ref:`key-event-handling`.
25252557
"""
25262558
if rcParams['toolbar'] != 'toolmanager':
25272559
key_press_handler(event, self.canvas, self.canvas.toolbar)
25282560

25292561
def button_press(self, event):
2530-
"""
2531-
The default Matplotlib button actions for extra mouse buttons.
2532-
"""
2562+
"""The default Matplotlib button actions for extra mouse buttons."""
25332563
if rcParams['toolbar'] != 'toolmanager':
25342564
button_press_handler(event, self.canvas, self.canvas.toolbar)
25352565

0 commit comments

Comments
 (0)