You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在IPython中使用mpld3.display()无法正常显示图形的问题求助

在IPython中使用mpld3.display()无法正常显示图形的问题求助

各位好,我最近在尝试用mpld3库做一个带交互式图例的绘图示例,代码写完运行后,只返回了一个HTML对象,完全看不到预期的图形,想请教下大家这是怎么回事,该怎么解决?

我的代码如下:

import mpld3
from mpld3 import plugins
from mpld3.utils import get_id
import numpy as np
import collections
import matplotlib.pyplot as plt

mpld3.enable_notebook()

N_paths = 5
N_steps = 100

x = np.linspace(0, 10, 100)
y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)
y = y.cumsum(1)

fig, ax = plt.subplots()
labels = ["a", "b", "c", "d", "e"]
line_collections = ax.plot(x, y.T, lw=4, alpha=0.2)

interactive_legend = plugins.InteractiveLegendPlugin(line_collections, labels)
plugins.connect(fig, interactive_legend)

mpld3.display()

运行后得到的结果只有这个对象,看不到任何图形:

Out[7]: <IPython.core.display.HTML object>

我已经调用了mpld3.enable_notebook(),但还是没效果,有没有大佬能指点下问题出在哪?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:18:08