Hi,
I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem.
// Note that plt.gca().figure == figure
... = FigureCanvasTkAgg(figure, ...)
plt.sca(plt.gca())
The problem is because FigureCanvasTkAgg(...) will call FigureCanvasBase.init(...) which resets the manager field needed in sca(). Below are the listing showing the problem:
class FigureCanvasBase:
def __init__(self, figure):
...
figure.set_canvas(self)
self.figure = figure
**# Here it is setting canvas.manager to None!!**
self.manager = None
...
def sca(ax):
"""
Set the current Axes to *ax* and the current Figure to the parent of *ax*.
"""
if not hasattr(ax.figure.canvas, "manager"):
raise ValueError("Axes parent figure is not managed by pyplot")
**# !!! ax.figure.canvas.manager is None!**
_pylab_helpers.Gcf.set_active(ax.figure.canvas.manager)
ax.figure.sca(ax)
For workaround, I checked out old version of sca(ax) from 3.2.2 and it seems to be working. On the other hand, I am not sure whether the old version is robust in v3.3.0 despite of this working situation.
def sca(ax):
"""
Set the current Axes instance to *ax*.
The current Figure is updated to the parent of *ax*.
"""
managers = _pylab_helpers.Gcf.get_all_fig_managers()
for m in managers:
if ax in m.canvas.figure.axes:
_pylab_helpers.Gcf.set_active(m)
m.canvas.figure.sca(ax)
return
raise ValueError("Axes instance argument was not found in a figure")
Please check and see whether bring back of old version of sca(ax) is a correct fix of this issue.
Hi,
I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem.
The problem is because FigureCanvasTkAgg(...) will call FigureCanvasBase.init(...) which resets the manager field needed in sca(). Below are the listing showing the problem:
For workaround, I checked out old version of sca(ax) from 3.2.2 and it seems to be working. On the other hand, I am not sure whether the old version is robust in v3.3.0 despite of this working situation.
Please check and see whether bring back of old version of sca(ax) is a correct fix of this issue.