Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove use of matplotlib.rc_context #1172

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions skrub/_reporting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re
import warnings

import matplotlib
import numpy as np
from matplotlib import pyplot as plt

Expand Down Expand Up @@ -51,9 +50,23 @@ def _plot(plotting_fun):

@functools.wraps(plotting_fun)
def plot_with_config(*args, **kwargs):
# This causes matplotlib to insert labels etc as text in the svg rather
# than drawing the glyphs.
with matplotlib.rc_context({"svg.fonttype": "none"}):
#
# Note: we do not use `matplotlib.rc_context` because it can prevent the
# inline display of plots in jupyter notebooks:
#
# https://github.com/matplotlib/matplotlib/issues/25041
# https://github.com/matplotlib/matplotlib/issues/26716
#
# otherwise we could write
# with matplotlib.rc_context({"svg.fonttype": "none"}):
#
# See https://github.com/skrub-data/skrub/pull/1172
#
original_font_type = plt.rcParams["svg.fonttype"]
try:
# This causes matplotlib to insert labels etc as text in the svg rather
# than drawing the glyphs.
plt.rcParams["svg.fonttype"] = "none"
with warnings.catch_warnings():
# We do not care about missing glyphs because the text is
# rendered & the viewbox is recomputed in the browser.
Expand All @@ -62,6 +75,8 @@ def plot_with_config(*args, **kwargs):
"ignore", "Matplotlib currently does not support Arabic natively"
)
return plotting_fun(*args, **kwargs)
finally:
plt.rcParams["svg.fonttype"] = original_font_type

return plot_with_config

Expand Down
Loading