Search code examples
matplotlibjupyter-notebookipywidgets

Jupyter notebook cells doesn't stretch to fit multiple plots


I am using matplotlib charts and ipywidgets to display plots in the ipynb. However When plotting multiple plots, the cells do not stretch to fit all the plots. Instead a scrollbar on the side shows. How can one enable the plots to stretch and fit on the cells?

with output:        
    clear_output()
    plot_a()
    plot_a()
    plot_a()

def plot_a():
    plt.bar(x, y)    
    plt.show()

Solution

  • You can use javascript magic for the help:

    %%javascript
    IPython.OutputArea.auto_scroll_threshold = 9999;
    

    Tested with and works:

    i = 0
    while i < 100:
        print('test')
        i +=1
    
    from matplotlib import pyplot as plt
    
    i = 0
    while i < 10:
        plt.plot([1,2])
        plt.show()
        i +=1