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.
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!
docker-compose.yml
Add the following to * docker-compose.yml * as a display setting.
docker-compose.yml
environment:
DISPLAY: host.docker.internal:0.0
If you need Japanese display, please add the following to * Dockerfile *.
RUN apt-get update && apt-get install -y fonts-ipafont
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.
Did the graph display successfully? ?? That's all, we hope that you can contribute to improving the development efficiency of everyone.
Recommended Posts