Skip to content

Commit dc62000

Browse files
authored
Merge pull request #1169 from mpmdean/cm-super-scipy-notebook
Add `cm-super` package install to `scipy-notebook` required for `matplotlib` latex labels.
2 parents 612aa57 + f527551 commit dc62000

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

scipy-notebook/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LABEL maintainer="Jupyter Project <[email protected]>"
77

88
USER root
99

10-
# ffmpeg for matplotlib anim & dvipng for latex labels
10+
# ffmpeg for matplotlib anim & dvipng+cm-super for latex labels
1111
RUN apt-get update && \
12-
apt-get install -y --no-install-recommends ffmpeg dvipng && \
12+
apt-get install -y --no-install-recommends ffmpeg dvipng cm-super && \
1313
rm -rf /var/lib/apt/lists/*
1414

1515
USER $NB_UID
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Matplotlit: Test tex fonts
2+
import matplotlib
3+
import matplotlib.pyplot as plt
4+
import os
5+
6+
matplotlib.rcParams['pgf.texsystem'] = 'pdflatex'
7+
matplotlib.rcParams.update({'font.family': 'serif', 'font.size': 18,
8+
'axes.labelsize': 20, 'axes.titlesize': 24,
9+
'figure.titlesize': 28})
10+
matplotlib.rcParams['text.usetex'] = True
11+
12+
fig, ax = plt.subplots(1, 1)
13+
x = [1, 2]
14+
y = [1, 2]
15+
ax.plot(x, y, label='a label')
16+
ax.legend(fontsize=15)
17+
18+
file_path = os.path.join("/tmp", "test_fonts.png")
19+
fig.savefig(file_path)
20+
print(f"File {file_path} saved")

scipy-notebook/test/test_matplotlib.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,30 @@ def test_matplotlib(container):
3333
cmd = running_container.exec_run(command)
3434
assert cmd.exit_code == 0, f"Command {command} failed"
3535
LOGGER.debug(cmd.output.decode("utf-8"))
36+
37+
38+
def test_matplotlib_fonts(container):
39+
"""Test matplotlib latex fonts, which depend on the cm-super package"""
40+
host_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
41+
"data")
42+
cont_data_dir = "/home/jovyan/data"
43+
test_file = "matplotlib_fonts_1.py"
44+
output_dir = "/tmp"
45+
LOGGER.info(f"Test cm-super latex labels in matplotlib ...")
46+
command = "sleep infinity"
47+
running_container = container.run(
48+
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
49+
tty=True,
50+
command=["start.sh", "bash", "-c", command],
51+
)
52+
command = f"python {cont_data_dir}/{test_file}"
53+
cmd = running_container.exec_run(command)
54+
assert cmd.exit_code == 0, f"Command {command} failed"
55+
LOGGER.debug(cmd.output.decode("utf-8"))
56+
# Checking if the file is generated
57+
# https://stackoverflow.com/a/15895594/4413446
58+
expected_file = f"{output_dir}/test_fonts.png"
59+
command = f"test -s {expected_file}"
60+
cmd = running_container.exec_run(command)
61+
assert cmd.exit_code == 0, f"Command {command} failed"
62+
LOGGER.debug(cmd.output.decode("utf-8"))

0 commit comments

Comments
 (0)