This project supports displaying matplotlib figures (e.g. plt.show()) from inside the DevContainer using X11 forwarding. Because containers are headless by default, some setup is needed on your host system.
🧪 Tested with
TkAggbackend on Alpine-based containers
- DevContainer with X11 libraries (already configured in the
Dockerfile) - An X11 server running on your host machine
DISPLAYenvironment variable set in.devcontainer/devcontainer.json
-
Install an X11 server We recommend VcXsrv
-
Launch VcXsrv with these settings:
Multiple windowsStart no client- ✅ Check Disable access control
-
Ensure your
.devcontainer/devcontainer.jsonincludes:"containerEnv": { "DISPLAY": "host.docker.internal:0" }
-
Rebuild the DevContainer
-
Test it Inside the DevContainer:
xclock # should open a clock window on your host python3 show_chunks.py # should display the stitched image
-
Install XQuartz: Download from https://www.xquartz.org
-
Start XQuartz, then enable network access:
defaults write org.xquartz.X11 enable_iglx -bool true xhost + 127.0.0.1 -
Update
.devcontainer/devcontainer.json:"containerEnv": { "DISPLAY": "host.docker.internal:0" }
-
Rebuild the DevContainer, then test as above.
Note
macOS support for X11 is less reliable — consider using plt.savefig() as a fallback.
-
Allow local X11 access:
xhost +local:
-
Expose your X11 socket to the container Add this to your Docker run config or override file:
volumes: - /tmp/.X11-unix:/tmp/.X11-unix environment: DISPLAY: :0
-
In
.devcontainer/devcontainer.json, set:"containerEnv": { "DISPLAY": ":0" }
-
Rebuild the container, and test
xclockand your Python script.
If GUI display is not possible, the script can be adapted to save instead:
plt.savefig("stitched_output.png")This allows contributors without GUI/X11 support to still see the result.
show_chunks.py— loads chunked images and displays them in a GUI windowDockerfile— includes X11 libraries and font packages.devcontainer/devcontainer.json— sets theDISPLAYenvironment variable