[PYTHON] Run matplotlib on a Windows Docker container

Introduction

Describes how to run matplotlib on a Windows Docker container. I tried Windows on Windows 10 Pro 64Bit version 2004. I also tried older versions. Docker Desktop can be WSL2 compliant or remains the same. Since it is in the Docker container, graphs such as matplotlib will not be displayed on the host side as it is. In order to display on the display on the host side (Windows side), I think that the container OS is linux, so it is necessary to start XServer on the Windows side and flow the display to that XServer.

Install VcXsrv

First, install * VcXsrv *. After installation, click * XL launch * under * VcXsrv * from the Windows menu. You can keep the default settings.

You should not need to configure * Firewall *. Also, if you run it on the same PC, it should not be necessary, but if you get an error due to authentication etc., please try the following.

Once started, you should see the VcXsrv X Server icon at the bottom right of the screen. Right-click on the icon and select Applications xclock from the menu that appears, and xclock should start as shown below! image.png

docker-compose.yml

Add the following to * docker-compose.yml * as a display setting.

docker-compose.yml


    environment:
      DISPLAY: host.docker.internal:0.0

Japanese display

If you need Japanese display, please add the following to * Dockerfile *.

RUN apt-get update && apt-get install -y fonts-ipafont

Program that was run

It looks like this as a running program.

test.py


import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-3, 3, 0.1)
y = np.sin(x)
fig = plt.plot(x, y)
plt.show()

matplotlib When you execute the above program in Docker, the following graph will be displayed. image.png

in conclusion

Did the graph display successfully? ?? That's all, we hope that you can contribute to improving the development efficiency of everyone.

Recommended Posts

Run matplotlib on a Windows Docker container
Run Matplotlib on a Docker container
Carry a Docker container
Run a Python file inside a Docker container on a remote Raspbian via PyCharm
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
How to run a Django application on a Docker container (development and production environment)
Launch Django on a Docker container with docker-compose up
Run IPython Notebook on Docker
Run Jupyter Notebook on windows
Run Tensorflow natively supported on windows
Run TensorFlow Docker Image on Python3
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Create a Linux environment on Windows 10
Run headless-chrome on a Debian-based image
How to delete a Docker container
Run XGBoost on Bash on Ubuntu on Windows
Run TensorFlow2 on a VPS server
Run Radeon GPU on Windows on QEMU / KVM
Run servo with Python on ESP32 (Windows)
Run TensorFlow on a GPU instance on AWS
Run a local script on a remote host
Creating a python virtual environment on Windows
Run py.test on Windows Anaconda and MinGW
Run Python code on A2019 Community Edition
I built a TensorFlow environment on windows10
Create a Linux virtual machine on Windows
Run a Python web application with Docker
Run Jupyter notebook on a remote server
A story about trying to run JavaScripthon on Windows and giving up.
Using graph drawing using Python's Matplotlib + Seaborn on Windows, a non-Python execution environment
Rock-paper-scissors with Python Let's run on a Windows local server for beginners
Put Docker in Windows Home and run a simple web server with Python
Build a LAMP environment on your local Docker
Periodically run a python program on AWS Lambda
Install and run Python3.5 + NumPy + SciPy on Windows 10
Run django applications on Windows + Apache + mod_wsgi + services.
Put MicroPython on Windows to run ESP32 on Python
Install Python3, numpy, pandas, matplotlib, etc. on Windows
Open a ZIP created on Windows in Linux
Simply build a Python 3 execution environment on Windows
Use the Kaggle API inside a Docker container
How to live a decent life on 2017 Windows
Try Python interactive mode inside a Docker container
Create a Python virtual development environment on Windows
Visualize grib2 on a map with python (matplotlib)
Until you create a machine learning environment with Python on Windows 7 and run it
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Run Kali Linux on Windows with GUI (without VirtualBox)
Run Tensorflow from Jupyter Notebook on Bash on Ubuntu on Windows
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
Until drawing a 3D graph in Python on windows10
Create a comfortable Python 3 (Anaconda) development environment on windows
A memo of installing Chainer 1.5 for GPU on Windows
Build a GVim-based Python development environment on Windows 10 (1) Installation
Procedure for building a CDK environment on Windows (Python)
Install Docker on Arch Linux and run it remotely
I'm a windows user but want to run tensorflow
Create a decent shell and python environment on Windows
A story about a Linux beginner putting Linux on a Windows tablet