3

I tried to create multiple mpld3 figures with a loop. However, nothing is produced:

import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
for i in range(0, 10):
    fig,ax=plt.subplots()
    ax.plot([1,3], [2,4], 'bo')
    mpld3.display(fig)

However, I can create figure if I use this code:

i=0
fig,ax=plt.subplots()
ax.plot([1,3], [2,4], 'bo')
mpld3.display(fig)

Also, I found that I wont get anything if the mpld3.display() is called in a if clause like this

if True: 
    fig,ax=plt.subplots()
    ax.plot([1,3], [2,4], 'bo')
    mpld3.display(fig)

But I can get the plot if I use

if True: 
    fig,ax=plt.subplots()
    ax.plot([1,3], [2,4], 'bo')
mpld3.display(fig)

Anyone knows why? I am using jupyter notebook.

Amber
  • 31
  • 2

0 Answers0