jupyter print plot and dataframe in order, for loop

Viewed 665

I want to print the dataframe and plots in the order as in the code in my jupyter notebook:

  • df
  • plot
  • df
  • plot

Currently, they are printed as:

  • df
  • df
  • plot
  • plot
from IPython.display import display
import matplotlib.pyplot as plt

df = pd.DataFrame({'x': range(5), 'y': range(5)})

for i in range(2):
    display(df)
    display(df.plot())

enter image description here

1 Answers

Force plt.show after you plot:

for i in range(2):
    display(df)
    df.plot()
    plt.show()
Related