只需要一行代码 mpld3.display()/mpld3.enable_notebook() 即可让 matplotlib/sdeaborn画的图有交互性
import numpy as np import matplotlib.pyplot as plt import mpld3 x=np.random.random(1000) y=np.random.random(1000) plt.hist2d(x,y,bins=(100,100)) mpld3.enable_notebook()
import seaborn as sns vp_df = pd.read_csv('https://raw.githubusercontent.com/visualpython/visualpython/main/visualpython/data/sample_csv/iris.csv') sns.scatterplot(x='sepal_length', y='sepal_width', data=vp_df, hue='variety') mpld3.display()
如果想让这样的交互图像去除交互性,只需mpld3.disable_notebook()即可