Skip to content

Instantly share code, notes, and snippets.

@maedoc
Last active November 12, 2018 10:53
Show Gist options
  • Save maedoc/b7b43c45ef1a8ef603879215b8010f0d to your computer and use it in GitHub Desktop.
Save maedoc/b7b43c45ef1a8ef603879215b8010f0d to your computer and use it in GitHub Desktop.
Matplotlib GUIs with PyCharm's console

Interactive Matplotlib Docker

This is a proof of concept for using a GUI backend for Matplotlib from a Docker image. It assumes Linux with X11. Specifically, this requires docker run with the the following extras

  • --net=host
  • -v /home/$USER/.Xauthority:/root/.Xauthority
  • -e DISPLAY=$DISPLAY

but these aren't options when using PyCharm's Python console, but one can use a docker-compose.yml to provide the equivalents, with the caveat that the $USER and $DISPLAY need to be updated, then configure a remote interpreter in PyCharm with the Docker Compose option pointing at the YAML file.

Non-Linux

The --net=host option isn't available outside Linux, so X11 forwarding could be used.

version: '2'
services:
python:
build: ./
network_mode: host
environment:
DISPLAY: "${DISPLAY}"
volumes:
- "${HOME}/.Xauthority:/root/.Xauthority"
FROM ubuntu
RUN apt-get update \
&& apt-get install -y python3-matplotlib python3-ipython
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment