Clearing all seaborn plots each time running the code in plots tab spyder IDE

Viewed 7500

I create some plots in one run of code, the plots are in plots tab. I tried to delete it all each time i rerun it but somehow the previous plots are still there not closing, it only creates new plots without clearing the previous plots from the previous run. I already tried to use plt.close('all') but it does not work. How do i clear all plots every time i rerun the code?

Here's my code

import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

plt.close('all')
avo_sales = pd.read_csv('avocados.csv')
avo_sales.rename(columns = {'4046':'small Hass sold','4225':'large Hass sold','4770':'xlarge Hass sold'},
                 inplace= True)

for column in avo_sales.columns[2:11]:
    sns.set()
    fig, ax = plt.subplots()
    sns.set(style="ticks")
    sns.boxplot(column, data= avo_sales)  # column is chosen here
    sns.despine(offset=10, trim=True)
2 Answers

I don't know how to even get Spyder to put plots in the plot pane, but here's a few things that might work.

  1. Try disabling some of the pane options:

enter image description here

  1. Try some magic functions:

%reset - reset everything

%matplotlib - puts all plots inline with your code in the interactive window

%clear - clears the interactive window

  1. Use IPython directly to help (via: https://gist.github.com/stsievert/8655158355b7155b2dd8):
from IPython import get_ipython

get_ipython().magic('reset -sf')
Related