我在Jupyter笔记本中有互动图,但是一旦我将笔记本上载到Github,这些图就不会显示在Github上,对此有何建议? 我什至保存笔记本的小部件状态。下面是一个示例交互式python绘图,如果您想尝试:
from IPython.html.widgets import *
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as wg
from IPython.display import display
from numpy import pi
def pltFunc(f):
plt.figure(figsize=(15,8))
x = np.arange(0,2*pi,0.01)
y1 = np.sin(2*np.pi*x*f)
y2 = np.cos(2*np.pi*x*g) + np.sin(np.pi*x*g)
plt.subplot(221)
plt.text(3, 2, r'$f(t) = \sin(2\pi \times$' + str((f)) + 't)' ,
{'color': 'b', 'fontsize': 16, 'ha': 'center', 'va': 'center',})
plt.plot(x, y1, 'b', linewidth=2)
plt.title('Sine Signal - change f')
plt.xlabel('t', {'color': 'k', 'fontsize': 20})
plt.ylabel('f(t)', {'color': 'k', 'fontsize': 20})
plt.ylim([-2.5,2.5])
plt.xlim([0,2*pi])
plt.xticks((0, pi, 2*pi), ('$0$','$\pi$','$2\pi$'), color='k', size=20)
plt.yticks((-2, 0, 2), ('-2','$0$','+2'), color='k', size=20)
plt.show()
f_slide = wg.FloatSlider(value=1.5,min=0,max=3,step=0.1)
interact(pltFunc, f = f_slide)
如果您将笔记本电脑以pdf格式下载为乳胶,即使它们没有出现