Скажем, у меня есть следующая простая функция для возврата объекта фигуры matplotlib:
import matplotlib.pyplot as plt
def return_mpl_fig(x,y):
mpl_fig = plt.figure()
ax = mpl_fig.add_subplot(111)
ax.plot(x,y)
return mpl_fig
Я могу преобразовать объект фигуры matplotlib в объект графической фигуры и построить его:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.tools as tls
x=[i for i in range(1,11)]
y=[i for i in range(1,11)]
mpl_fig = return_mpl_fig(x,y)
plotly_fig = tls.mpl_to_plotly(mpl_fig)
init_notebook_mode(connected=True)
iplot(plotly_fig)

Но если вместо простой функции я сделаю ее рекурсивной функцией, она дополнительно отобразит пустую фигуру:
import matplotlib.pyplot as plt
def return_mpl_fig(x,y):
mpl_fig = plt.figure()
ax = mpl_fig.add_subplot(111)
if len(x)>5:
return return_mpl_fig(x[:5],y[:5])
ax.plot(x,y)
return mpl_fig
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.tools as tls
x=[i for i in range(1,11)]
y=[i for i in range(1,11)]
mpl_fig = return_mpl_fig(x,y)
plotly_fig = tls.mpl_to_plotly(mpl_fig)
init_notebook_mode(connected=True)
iplot(plotly_fig)

Почему это? И как мне это предотвратить?