Dockerfile
FROM python:3.6.2
RUN apt-get update \
&& apt-get install -y \
git \
unzip \
&& rm -rf /var/lib/apt/lists/*
#Install Ricty Diminished as a font.
WORKDIR /usr/share/fonts
ENV RICTY_DIMINISHED_VERSION 3.2.4
ADD https://github.com/mzyy94/RictyDiminished-for-Powerline/archive/$RICTY_DIMINISHED_VERSION-powerline-early-2016.zip .
RUN unzip -jo $RICTY_DIMINISHED_VERSION-powerline-early-2016.zip \
&& fc-cache -fv
#Prepare a configuration file for Matplotlib.
WORKDIR /etc
RUN echo "backend : Agg" >> matplotlibrc \
&& echo "font.family : Ricty Diminished" >> matplotlibrc
#Install Matplotlib.
WORKDIR /opt/app
ENV MATPLOTLIB_VERSION 2.0.2
RUN pip install matplotlib==$MATPLOTLIB_VERSION
#Copy the sample script using Matplotlib.
COPY plot.py .
docker-compose.yml
version: '3.3'
services:
plot:
build: .
environment:
MPLCONFIGDIR: /etc
volumes:
- .:/opt/data-volume
working_dir: /opt/data-volume
entrypoint:
- python
- /opt/app/plot.py
plot.py
from matplotlib import pyplot as plt
if __name__ == '__main__':
labels = ['sardine', 'mackerel', 'pike', 'Oarfish']
x = list(range(1, len(labels) + 1))
y = [1, 3, 5, 15]
plt.bar(x, y, align='center')
plt.xticks(x, labels, rotation='vertical')
plt.xlabel('Types of fish')
plt.ylabel('strength(pt)')
plt.tight_layout()
plt.savefig('plot.png')
Recommended Posts