python - 为什么 jupyter-notebook 不运行交互式绘图?
问题描述
我已经看到jupyter-lab
可以显示一些交互式绘图,例如plot.ly或altair,但是当我在其中绘制相同的代码时jupyter-notebook
,没有任何绘图
import altair as alt
from vega_datasets import data
source = data.cars()
alt.Chart(source).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
size='Acceleration'
)
输出只是一个VegaLite 2 对象,但没有任何绘图。
为什么我不能使用 jupyter-notebook 来绘制交互图?
解决方案
要在 Jupyter Notebook(不是 JupyterLab)中显示 altair 图,您需要安装vega python 包并通过运行alt.renderers.enable('notebook')
. Altair 的安装说明中明确提到了这一点。
Altair 的文档中提供了更多故障排除信息,包括您所看到的特定输出的故障排除。
推荐阅读
- php - 尝试在 null laravel 8 上读取属性“id”
- android - Android 原生合约测试
- javascript - JavaScript 中最小的未使用 ID
- javascript - axios 无法发送带有 cookie 的请求
- java - 使用关联程序打开文件不会在引号中发送其路径
- python - 如何使用自动映射正确处理多个连接路径?
- angular - Angular SVG 图标不适用于 Angular Universal 项目延迟加载模块
- php - 为什么 PHP DateTime->add(DateInterval) 在夏令时转换失败?
- c# - 在 Azure 函数中获取要读取的文件路径
- r - 如何通过使用 R for 循环调用函数来填充空矩阵?