中文
在 VSCode 侧边栏中按序排列显示 matplotlib 生成的图表,类似 PyCharm 的 SciView。运行 Python 脚本时,plt.show() 不再弹出独立窗口,而是将所有 figure 渲染显示在侧边栏中,并支持导出为 PNG / SVG / PDF。

用法
- 打开任意
.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 注入,所有集成终端自动继承。
功能特性
- 拦截
plt.show() 和 fig.show(),自动捕获所有 figure 到侧边栏
- 图表按序垂直排列,带序号、标题、时间戳
- 点击图表在新面板中放大预览,支持滚轮缩放、按钮缩放、拖拽平移
- 预览面板支持多图导航(‹ / › 按钮或 ←/→ 方向键切换)
- 预览面板优先使用 SVG 矢量格式,放大时不失真
- 预览面板显示图表元信息(尺寸、DPI)
- 导出图表为 PNG / SVG / PDF 格式(侧边栏与预览面板均可触发)
- 复制图片到系统剪贴板(侧边栏与预览面板均可触发)
- 在系统文件管理器中定位图表文件
- 并排对比两张图表(分栏独立缩放,可拖动分隔线)
- 按标题搜索/过滤图表
- 图表重命名(双击标题或按钮触发)
- 文件夹分组管理(创建文件夹、拖拽图表到文件夹、折叠/展开)
- 跨会话持久化:重启 VSCode 后自动恢复图表
- 深色主题背景模式(
default / transparent / dark)
- 单张删除、一键清除所有图表(带确认弹窗)
- 自动适配深色 / 浅色主题
- 非阻塞:
plt.show() 后脚本继续执行
- 自动检测系统 CJK 字体,中文 / 日文 / 韩文标签正常显示
- 禁用 / 卸载扩展时自动清除环境变量,不影响 Python 脚本正常运行
环境要求
- VSCode 1.74 或更高版本
- Python 3
- matplotlib
配置项
| 配置项 |
默认值 |
说明 |
figureViewer.autoCapture |
true |
自动注入 matplotlib backend 环境变量到所有集成终端,运行 python script.py 时自动捕获图表。 |
figureViewer.adjustCodeRunner |
false |
启用后自动将 Code Runner 的 runInTerminal 设为 true,使其在终端中运行以继承环境变量。 |
figureViewer.maxStoredFigures |
100 |
保存的图表数量上限,超过后自动删除最旧的。 |
figureViewer.chartBackground |
default |
图表背景颜色:default 白色 / transparent 透明 / dark 深色(适配深色主题)。 |
figureViewer.thumbnailWidth |
0 |
侧边栏缩略图宽度(像素),0 为自适应填满卡片。 |
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() 和 fig.show() 触发的 figure;脚本内显式调用 matplotlib.use(...) 会覆盖注入的 backend。
- 通过
Figure() 直接创建(非 plt.figure())的 figure 没有 manager,fig.show() 会抛出 AttributeError,此为 matplotlib 原生行为。
chartBackground 配置变更仅对新打开的终端生效,已打开的终端不会自动更新。
许可证
本项目基于 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 and displayed in the sidebar, with support for exporting as PNG / SVG / PDF.

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.
Features
- Intercepts
plt.show() and fig.show() to capture 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
- Multi-chart navigation in preview panel (‹ / › buttons or ←/→ arrow keys)
- SVG vector format preferred in preview for lossless zooming
- Preview panel displays chart metadata (size, DPI)
- Export figures as PNG / SVG / PDF (triggered from sidebar or preview panel)
- Copy image to system clipboard (from sidebar or preview panel)
- Reveal chart file in system file explorer
- Side-by-side comparison of two charts (independent zoom, draggable divider)
- Search/filter charts by title
- Rename charts (double-click title or button trigger)
- Folder organization (create folders, drag charts to folders, collapse/expand)
- Cross-session persistence: charts restored after VSCode restart
- Dark theme background mode (
default / transparent / dark)
- Delete individual figures or clear all at once (with confirmation dialog)
- 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
Configuration
| Setting |
Default |
Description |
figureViewer.autoCapture |
true |
Automatically injects matplotlib backend env vars into all integrated terminals to capture figures when running python script.py. |
figureViewer.adjustCodeRunner |
false |
When enabled, automatically sets Code Runner's runInTerminal to true so it runs in terminal to inherit env vars. |
figureViewer.maxStoredFigures |
100 |
Max number of charts to keep; oldest are auto-deleted when exceeded. |
figureViewer.chartBackground |
default |
Chart background: default white / transparent / dark (for dark theme). |
figureViewer.thumbnailWidth |
0 |
Sidebar thumbnail width in pixels; 0 for adaptive (fill card). |
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() and fig.show(); explicitly calling matplotlib.use(...) in the script overrides the injected backend.
- Figures created via
Figure() directly (not plt.figure()) have no manager; fig.show() raises AttributeError — this is matplotlib's native behavior.
chartBackground configuration changes only take effect for newly opened terminals; existing terminals are not automatically updated.
License
This project is licensed under the MIT License - see the LICENSE file for details