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
相关产品推荐
相关产品推荐

