You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@zjpoh thanks for bringing this to our attention, and you're right this certainly can be a problem. Unfortunately, there isn't as easy a solution as there seems at first glance.
Matplotlib has two primary "global" drawing concepts - the figure and the axes. The figure holds one or more axes and is what is rendered, sized, and manipulated with event handlers. The axes is the canvas that we draw artists on. Most individual visualizers are drawn on only a single axes object, and similar to the pandas and seaborn APIs, they take an axes object that they can draw on. By default, ax=None and so to get the axes, the visualizer calls plt.gca -- get current axes; and that's what's causing what you're observing above.
This means that the primary way we resolve this issue is as follows:
importmatplotlib.pyplotasplt# First figure fig, ax=plt.subplots(figsize=(9,6))
viz=Visualizer(ax=ax)
viz.fit_transform(X, y)
viz.poof()
# Second figure fig2, ax2=plt.subplots(figsize=(9,6))
viz2=Visualizer(ax=ax2)
...
The primary way we do this is so that we can compose multiple visualizers as a single figure, e.g. the GridVisualizer and FlipBookVisualizer. Very often in my code you'll see:
As a result, we've been very careful not to do anything with the figure in Yellowbrick code, jumping through a lot of hoops in the ResidualsPlot, JointPlot, and InterclusterDistance visualizers to ensure that we're only drawing on the axes specified ...
That doesn't mean that we don't need to solve this problem -- the question is how. I'll comment on clearing the figure in the PR you opened, which by the way - thanks! I really appreciate that you opened the issue and submitted a PR!
Describe the bug
When making consecutive plots in python script, the older plots are still visible.
To Reproduce
In
doc/api/target/
,Expected behavior
Traceback
The second plot contains the first plot.
This can be solved by adding
plt.gcf().clear()
afterviz.poof()
.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: