Skip to content

add documentation for figure show method in backend_bases and backend_template #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,24 @@ def get_backend():
"Returns the current backend."
return rcParams['backend']


class NonGUIBackendWarning(Warning):
pass


def _warn_non_gui_show():
warnings.warn(
"matplotlib is currently using a non-GUI backend, "
"so the figure can not be shown. Call "
"matplotlib.hide_show_warnings() to suppress "
"these warnings.",
NonGUIBackendWarning)


def hide_show_warnings():
warnings.simplefilter('ignore', NonGUIBackendWarning)


def interactive(b):
"""
Set interactive mode to boolean b.
Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from matplotlib import rcParams
from matplotlib import is_interactive
from matplotlib._pylab_helpers import Gcf
from matplotlib import _warn_non_gui_show

from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
import cStringIO
Expand Down Expand Up @@ -2423,13 +2424,19 @@ def __init__(self, canvas, num):
self.key_press)
"""
The returned id from connecting the default key handler via :meth:`FigureCanvasBase.mpl_connnect`.

To disable default key press handling::

manager, canvas = figure.canvas.manager, figure.canvas
canvas.mpl_disconnect(manager.key_press_handler_id)


"""

def show(self):
"""
For GUI backends, show the figure window and redraw.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is some monkey patching, this method is not called from the interactive backends, right? Perhaps this would be a good place to state this.

"""
_warn_non_gui_show()

def destroy(self):
pass
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from matplotlib.text import Text, _process_text_args
from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
TransformedBbox)
from matplotlib import _warn_non_gui_show


docstring.interpd.update(projection_names = get_projection_names())
Expand Down Expand Up @@ -328,6 +329,19 @@ def __init__(self,
self.clf()
self._cachedRenderer = None

def show(self):
"""
If using a GUI backend, display the figure window.

For non-GUI backends, this does nothing.
"""
if hasattr(self, 'canvas'):
manager = getattr(self.canvas, 'manager', None)
if manager is not None:
manager.show()
return
_warn_non_gui_show()

def _get_axes(self):
return self._axstack.as_list()

Expand Down