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

Skip to content

Fix draw on show #4503

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

Merged
merged 6 commits into from
Jun 28, 2015
Merged
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
3 changes: 1 addition & 2 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_num_fig_managers(cls):
"""
Return the number of figures being managed.
"""
return len(cls.figs.values())
return len(cls.figs)

@classmethod
def get_active(cls):
Expand Down Expand Up @@ -146,7 +146,6 @@ def draw_all(cls, force=False):
state machine.
"""
for f_mgr in cls.get_all_fig_managers():
# TODO add logic to check if figure is stale
if force or f_mgr.canvas.figure.stale:
f_mgr.canvas.draw_idle()

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def destroy(*args):
self.window.connect("delete_event", destroy)
if matplotlib.is_interactive():
self.window.show()
self.canvas.draw_idle()

def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def destroy(*args):
self.window.connect("delete_event", destroy)
if matplotlib.is_interactive():
self.window.show()
self.canvas.draw_idle()

def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def notify_axes_change(fig):

if matplotlib.is_interactive():
self.show()
self.canvas.draw_idle()

def close(self):
Gcf.destroy(self.num)
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# that changes made maintain expected behaviour.

from base64 import b64encode
from contextlib import contextmanager
import json
import io
import os
Expand All @@ -18,7 +17,7 @@

from matplotlib import rcParams
from matplotlib.figure import Figure
from matplotlib.backends import backend_agg
from matplotlib import is_interactive
from matplotlib.backends.backend_webagg_core import (FigureManagerWebAgg,
FigureCanvasWebAggCore,
NavigationToolbar2WebAgg)
Expand All @@ -29,7 +28,6 @@
class Show(ShowBase):
def __call__(self, block=None):
from matplotlib._pylab_helpers import Gcf
from matplotlib import is_interactive

managers = Gcf.get_all_fig_managers()
if not managers:
Expand All @@ -54,7 +52,6 @@ def __call__(self, block=None):


def draw_if_interactive():
from matplotlib import is_interactive
import matplotlib._pylab_helpers as pylab_helpers

if is_interactive():
Expand Down Expand Up @@ -227,6 +224,9 @@ def new_figure_manager_given_figure(num, figure):
if rcParams['nbagg.transparent']:
figure.patch.set_alpha(0)
manager = FigureManagerNbAgg(canvas, num)
if is_interactive():
manager.show()
figure.canvas.draw_idle()
return manager


Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def __init__(self, canvas, num):

if matplotlib.is_interactive():
self.window.show()
self.canvas.draw_idle()

def notify_axes_change(fig):
# This will be called whenever the current axes is changed
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def new_figure_manager_given_figure(num, figure):
figManager = FigureManagerTkAgg(canvas, num, window)
if matplotlib.is_interactive():
figManager.show()
canvas.draw_idle()
return figManager


Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ def new_figure_manager_given_figure(num, figure):
figmgr = frame.get_figure_manager()
if matplotlib.is_interactive():
figmgr.frame.Show()
figure.canvas.draw_idle()
Copy link
Member

Choose a reason for hiding this comment

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

I seem to recall that draw_idle() in wx can be broken sometimes. Would it make sense to make all of these be figure.canvas.draw() instead as this isn't a performance-critical portion of the code? We should probably guarantee an image upon initial display.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mdehoon convinced me that in almost all cases we want to use draw_idle to play nice with the crankier event loops (and most of the backends have some 'I have been told to draw, but have not' so the later calls to draw_idle get no-oped, rather than stacking up draw commands.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, now re-reading this and understanding it correctly. I think you are reffering to the issue fixed by #3905 so I am inclined to leave this as-is unless a Wx users says otherwise.


return figmgr

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_wxagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def new_figure_manager_given_figure(num, figure):
figmgr = frame.get_figure_manager()
if matplotlib.is_interactive():
figmgr.frame.Show()
figure.canvas.draw_idle()
return figmgr


Expand Down
35 changes: 16 additions & 19 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ def gcf():
else:
return figure()


def fignum_exists(num):
return _pylab_helpers.Gcf.has_fignum(num) or num in get_figlabels()

Expand Down Expand Up @@ -1138,20 +1139,20 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
sharey = "none"
share_values = ["all", "row", "col", "none"]
if sharex not in share_values:
# This check was added because it is very easy to type subplots(1, 2, 1)
# when subplot(1, 2, 1) was intended. In most cases, no error will
# ever occur, but mysterious behavior will result because what was
# intended to be the subplot index is instead treated as a bool for
# sharex.
# This check was added because it is very easy to type
# `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended.
# In most cases, no error will ever occur, but mysterious behavior will
# result because what was intended to be the subplot index is instead
# treated as a bool for sharex.
if isinstance(sharex, int):
warnings.warn("sharex argument to subplots() was an integer."
" Did you intend to use subplot() (without 's')?")

raise ValueError("sharex [%s] must be one of %s" % \
(sharex, share_values))
raise ValueError("sharex [%s] must be one of %s" %
(sharex, share_values))
if sharey not in share_values:
raise ValueError("sharey [%s] must be one of %s" % \
(sharey, share_values))
raise ValueError("sharey [%s] must be one of %s" %
(sharey, share_values))
if subplot_kw is None:
subplot_kw = {}
if gridspec_kw is None:
Expand All @@ -1167,10 +1168,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,

# Create first subplot separately, so we can share it if requested
ax0 = fig.add_subplot(gs[0, 0], **subplot_kw)
#if sharex:
# subplot_kw['sharex'] = ax0
#if sharey:
# subplot_kw['sharey'] = ax0
axarr[0] = ax0

r, c = np.mgrid[:nrows, :ncols]
Expand Down Expand Up @@ -1203,15 +1200,13 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,

# turn off redundant tick labeling
if sharex in ["col", "all"] and nrows > 1:
#if sharex and nrows>1:
# turn off all but the bottom row
for ax in axarr[:-1, :].flat:
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.offsetText.set_visible(False)

if sharey in ["row", "all"] and ncols > 1:
#if sharey and ncols>1:
# turn off all but the first column
for ax in axarr[:, 1:].flat:
for label in ax.get_yticklabels():
Expand All @@ -1222,8 +1217,8 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
# Reshape the array to have the final desired dimension (nrow,ncol),
# though discarding unneeded dimensions that equal 1. If we only have
# one subplot, just return it instead of a 1-element array.
if nplots==1:
ret = fig, axarr[0,0]
if nplots == 1:
ret = fig, axarr[0, 0]
else:
ret = fig, axarr.squeeze()
else:
Expand Down Expand Up @@ -1257,10 +1252,12 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
bbox = a.bbox
byebye = []
for other in fig.axes:
if other==a: continue
if other == a:
continue
if bbox.fully_overlaps(other.bbox):
byebye.append(other)
for ax in byebye: delaxes(ax)
for ax in byebye:
delaxes(ax)

return a

Expand Down