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

Jupyter Notebook 7.1.3中%matplotlib魔法函数使用问题求助

针对Jupyter 7.1.3 + Python 3.11.7下matplotlib魔法函数异常的解决方案
  • 检查并升级matplotlib版本
    安装与当前环境兼容的matplotlib版本(推荐3.7.x系列):

    pip install --upgrade matplotlib==3.7.5
    
  • 重置Jupyter配置文件
    覆盖生成新的配置文件,修复可能损坏的配置:

    jupyter notebook --generate-config --overwrite
    
  • 切换matplotlib后端
    若%matplotlib notebook/inline失效,尝试切换到tkagg后端测试:

    %matplotlib tkagg
    import matplotlib.pyplot as plt
    plt.plot([1,2,3])
    plt.show()
    

    若正常显示,可将该后端设为默认:找到生成的jupyter_notebook_config.py,添加一行:

    c.InteractiveShellApp.matplotlib = 'tkagg'
    
  • 重新关联ipykernel
    确保当前Python环境的内核正确注册到Jupyter:

    pip install ipykernel
    python -m ipykernel install --user --name=current_env
    

    重启Jupyter后选择对应内核运行。

  • 用干净虚拟环境排查干扰
    创建仅含必要依赖的虚拟环境,排除其他包冲突:

    python -m venv clean_env
    # Windows系统执行:clean_env\Scripts\activate
    source clean_env/bin/activate
    pip install jupyter==7.1.3 matplotlib==3.7.5 ipykernel
    jupyter notebook
    

    在该环境中测试魔法函数是否正常工作。

内容的提问来源于stack exchange,提问作者Binay

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 18:52:02