From 054fa72d3d333b8655d696f72752472a59e2115d Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Tue, 3 Dec 2024 13:33:17 +0100 Subject: [PATCH 1/4] remove use of matplotlib.rc_context --- skrub/_reporting/_plotting.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/skrub/_reporting/_plotting.py b/skrub/_reporting/_plotting.py index e1e4b58f0..e2f75e07c 100644 --- a/skrub/_reporting/_plotting.py +++ b/skrub/_reporting/_plotting.py @@ -8,7 +8,6 @@ import re import warnings -import matplotlib import numpy as np from matplotlib import pyplot as plt @@ -51,9 +50,16 @@ 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"}): + # + # TODO once this is fixed: https://github.com/matplotlib/matplotlib/issues/25041 + # use the context manager: + # with matplotlib.rc_context({"svg.fonttype": "none"}): + # + svg_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. @@ -62,6 +68,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"] = svg_font_type return plot_with_config From 3021c67d0f84f27c8e096b6ade41a280d94d8d3a Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Tue, 3 Dec 2024 13:44:03 +0100 Subject: [PATCH 2/4] _ --- skrub/_reporting/_plotting.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/skrub/_reporting/_plotting.py b/skrub/_reporting/_plotting.py index e2f75e07c..be5e81c31 100644 --- a/skrub/_reporting/_plotting.py +++ b/skrub/_reporting/_plotting.py @@ -51,11 +51,18 @@ def _plot(plotting_fun): @functools.wraps(plotting_fun) def plot_with_config(*args, **kwargs): # - # TODO once this is fixed: https://github.com/matplotlib/matplotlib/issues/25041 - # use the context manager: + # Note: we do 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"}): # - svg_font_type = plt.rcParams["svg.fonttype"] + # 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. @@ -69,7 +76,7 @@ def plot_with_config(*args, **kwargs): ) return plotting_fun(*args, **kwargs) finally: - plt.rcParams["svg.fonttype"] = svg_font_type + plt.rcParams["svg.fonttype"] = original_font_type return plot_with_config From 717e0934baf18242bbdc0863c192cf27d6fd4f64 Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Tue, 3 Dec 2024 13:50:52 +0100 Subject: [PATCH 3/4] _ --- skrub/_reporting/_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skrub/_reporting/_plotting.py b/skrub/_reporting/_plotting.py index be5e81c31..6a4daadbb 100644 --- a/skrub/_reporting/_plotting.py +++ b/skrub/_reporting/_plotting.py @@ -51,7 +51,7 @@ def _plot(plotting_fun): @functools.wraps(plotting_fun) def plot_with_config(*args, **kwargs): # - # Note: we do use `matplotlib.rc_context` because it can prevent the + # 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 From ca3c6a652a7c61054ae7a04fd321c45467afa1ca Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Mon, 9 Dec 2024 13:10:28 +0100 Subject: [PATCH 4/4] changelog --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1de6d3e93..03f16dd7e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -32,6 +32,11 @@ Changes Bug fixes --------- +* Generating a ``TableReport`` could have an effect on the matplotib + configuration which could cause plots not to display inline in jupyter + notebooks any more. This has been fixed in skrub in :pr:`1172` by + :user:`Jérôme Dockès ` and the matplotlib issue can be tracked + [here](https://github.com/matplotlib/matplotlib/issues/25041). Release 0.4.0