Remove past Matplotlib plots in the same cell in Jupyter Notebook involving interactive widgets

后端 未结 1 846
悲哀的现实
悲哀的现实 2021-01-02 23:11

this is just a small problem that has been bugging me for a while.

I have a pandas dataframe consisting of all continuous variables. I want to draw a scatter plot (u

相关标签:
1条回答
  • 2021-01-02 23:43

    You may add plt.show() at the end of your function. This replots the graph in the same cell instead of adding a new one.

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    from ipywidgets import interactive
    %matplotlib inline
    
    columns=['a','b','c']
    data = np.cumsum(np.random.rand(10,3),axis=1)
    df = pd.DataFrame(data,columns=columns)
    
    def g(x,y):
        plt.scatter(df[x], df[y])
        plt.show()
    
    interactive_plot = interactive(g, x=columns, y=columns)
    interactive_plot
    

    0 讨论(0)
提交回复
热议问题