中文
在 VSCode 侧边栏中按序排列显示 matplotlib 生成的图表,类似 PyCharm 的 SciView。运行 Python 脚本时,plt.show() 不再弹出独立窗口,而是将所有 figure 渲染为 PNG 并显示在侧边栏中。
功能特性
- 拦截
plt.show(),自动捕获所有 figure 到侧边栏
- 图表按序垂直排列,带序号、标题、时间戳
- 点击图表在新面板中放大预览,支持滚轮缩放、按钮缩放、拖拽平移
- 单张删除、一键清除所有图表
- 自动适配深色 / 浅色主题
- 非阻塞:
plt.show() 后脚本继续执行
- 自动检测系统 CJK 字体,中文 / 日文 / 韩文标签正常显示
- 禁用 / 卸载扩展时自动清除环境变量,不影响 Python 脚本正常运行
环境要求
- VSCode 1.74 或更高版本
- Python 3
- matplotlib
用法
- 打开任意
.py 文件(含 matplotlib 绘图代码)。
- 使用 VSCode 内置的 Run Python File、Code Runner 或终端中直接运行
python script.py。
- 图表会自动出现在侧边栏 "Figure Viewer" 面板中。
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.title("示例图")
plt.show()
print("show 之后的代码继续执行")
扩展自动适配 conda 环境,无需手动配置。环境变量通过 VSCode 的 environmentVariableCollection API 注入,所有集成终端自动继承。
配置项
| 配置项 |
默认值 |
说明 |
figureViewer.autoCapture |
true |
自动在所有集成终端中注入 matplotlib backend 环境变量,使普通 python script.py 运行时图表自动捕获。关闭后恢复原始终端环境。 |
figureViewer.adjustCodeRunner |
false |
启用后,若检测到 Code Runner 扩展,自动将 code-runner.runInTerminal 设为 true。默认关闭,扩展不会修改 Code Runner 的任何设置。 |
Code Runner 用户
如果你使用 Code Runner 扩展运行 Python 脚本,需要确保 Code Runner 在终端中运行(而非输出面板),因为只有终端才能继承自动捕获的环境变量。
方式一:让 Figure Viewer 自动设置
在设置中启用 figureViewer.adjustCodeRunner,扩展会自动将 Code Runner 的 runInTerminal 设为 true。
方式二:手动设置
- 打开设置:
Ctrl + ,(Windows / Linux)或 Cmd + ,(macOS)
- 搜索
code-runner.runInTerminal
- 勾选该选项
或在 settings.json 中添加:
"code-runner.runInTerminal": true
提示:runInTerminal: false(在输出面板运行)不支持图表捕获,因为输出面板不继承终端环境变量。
已知限制
- 仅捕获
plt.show() 触发的 figure;脚本内显式调用 matplotlib.use(...) 会覆盖注入的 backend。
- 纯面向对象路径
fig.show() 在当前版本不保证捕获。
- 图表仅在当前 VSCode 会话内有效,不跨会话恢复。
- 多个 VSCode 窗口同时运行时,端口文件可能被后启动的窗口覆盖(仅最后启动的窗口有效捕获)。
许可证
本项目基于 MIT 许可证开源 - 详见 LICENSE 文件
English
Display matplotlib figures in the VSCode sidebar, similar to PyCharm's SciView. When running Python scripts, plt.show() no longer pops up a separate window — all figures are rendered as PNG and displayed in the sidebar.
Features
- Intercepts
plt.show() and captures all figures to the sidebar
- Figures arranged vertically with index, title, and timestamp
- Click a figure to open a zoomable preview panel with scroll zoom, button zoom, and drag panning
- Delete individual figures or clear all at once
- Automatic light / dark theme adaptation
- Non-blocking: script continues executing after
plt.show()
- Auto-detects system CJK fonts for Chinese / Japanese / Korean labels
- Environment variables automatically cleaned up on disable / uninstall
Requirements
- VSCode 1.74 or higher
- Python 3
- matplotlib
Usage
- Open any
.py file with matplotlib plotting code.
- Run it using VSCode's built-in Run Python File, Code Runner, or
python script.py in the terminal.
- Figures will automatically appear in the "Figure Viewer" sidebar panel.
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.title("Example Plot")
plt.show()
print("code after show() continues to execute")
The extension automatically adapts to conda environments. Environment variables are injected via VSCode's environmentVariableCollection API and inherited by all integrated terminals.
Configuration
| Setting |
Default |
Description |
figureViewer.autoCapture |
true |
Automatically injects matplotlib backend environment variables into all integrated terminals, capturing figures when running python script.py. Disable to restore the original terminal environment. |
figureViewer.adjustCodeRunner |
false |
When enabled, automatically sets code-runner.runInTerminal to true if Code Runner is detected. Off by default — the extension will not modify any Code Runner settings. |
Code Runner Users
If you use the Code Runner extension to run Python scripts, ensure Code Runner runs in the terminal (not the output panel), because only terminals inherit the auto-capture environment variables.
Option 1: Let Figure Viewer set it automatically
Enable figureViewer.adjustCodeRunner in settings, and the extension will set Code Runner's runInTerminal to true.
Option 2: Set it manually
- Open Settings:
Ctrl + , (Windows / Linux) or Cmd + , (macOS)
- Search for
code-runner.runInTerminal
- Check the option
Or add to settings.json:
"code-runner.runInTerminal": true
Tip: runInTerminal: false (running in the output panel) does not support figure capture, because the output panel does not inherit terminal environment variables.
Known Issues
- Only captures figures triggered by
plt.show(); explicitly calling matplotlib.use(...) in the script overrides the injected backend.
- The object-oriented path
fig.show() is not guaranteed to be captured in this version.
- Figures are only valid for the current VSCode session and do not persist across sessions.
- When multiple VSCode windows are running simultaneously, the port file may be overwritten by the window started last (only the last window captures figures).
License
This project is licensed under the MIT License - see the LICENSE file for details