✔ 14:16:01 $ git diff
diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py
index f5c86de126..1e94d90d15 100644
--- a/lib/matplotlib/pyplot.py+++ b/lib/matplotlib/pyplot.py@@ -263,7 +263,6 @@ def switch_backend(newbackend):
backend_mod = importlib.import_module(
cbook._backend_module_name(newbackend))
- canvas_class = backend_mod.FigureCanvas
required_framework = _get_required_interactive_framework(backend_mod)
if required_framework is not None:
@@ -293,6 +292,8 @@ def switch_backend(newbackend):
# also update backend_mod accordingly; also, per-backend customization of
# draw_if_interactive is disabled.
if new_figure_manager is None:
+ # only try to get the canvas class if have opted into the new scheme+ canvas_class = backend_mod.FigureCanvas
def new_figure_manager_given_figure(num, figure):
return canvas_class.new_manager(figure, num)
I do not think this PR fixes the problem, after applying the changes, now exception is thrown on Line 185
line 185, in _get_required_interactive_framework
if not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"):
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?
def _get_required_interactive_framework(backend_mod):
if not hasattr(backend_mod, 'FigureCanvas') or not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"):
_api.warn_deprecated(
"3.6", name="Support for FigureCanvases without a "
"required_interactive_framework attribute")
return None
# Inline this once the deprecation elapses.
return backend_mod.FigureCanvas.required_interactive_framework
Can confirm this is still an issue with matplotlib 3.6.0 on python 3.10 in PyCharm 2022.2.2
Reacted by Josua Müller, Sean Grogan, Andrea Lacava, MaurusGubser, Gardes Frédéric, Marcus Ong, Roman Titov, Arman Haghanifar, Null2947, BKI92 and 4 more
import matplotlib.pyplot as plt
pizza, marshmallows = plt.subplots(1, 1)
print(pizza)
Error
Traceback (most recent call last):
File "F:\gt_stats_iii\scipy_stats_binom_examples.py", line 8, in <module>
pizza, marshmallows = plt.subplots(1, 1)
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 1430, in subplots
fig = figure(**fig_kw)
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 771, in figure
manager = new_figure_manager(
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 346, in new_figure_manager
_warn_if_gui_out_of_main_thread()
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 336, in _warn_if_gui_out_of_main_thread
if (_get_required_interactive_framework(_get_backend_mod()) and
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 206, in _get_backend_mod
switch_backend(dict.__getitem__(rcParams, "backend"))
File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 266, in switch_backend
canvas_class = backend_mod.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?
Process finished with exit code 1
Reacted by MaurusGubser, Gardes Frédéric, MS511, Arman Haghanifar, vanamalivanam, Eleonora, JanDudek, Thiago S. Gouvêa, Wang Ziming, Yak0vkaSup and 1 more
Not having a FigureCanvas class as a backend was deprecated in mpl 3.6 and expired in 3.8, it looks like the most recent versions of PyCharm do have it, so perhaps you need to update?
Activity
tacaswell commented on Sep 16, 2022
Does this change make it work?
FIX: only expect FigureCanvas on backend module if using new style
TLCFEM commented on Sep 16, 2022
I do not think this PR fixes the problem, after applying the changes, now exception is thrown on Line 185
line 185, in _get_required_interactive_framework if not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"): AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?TLCFEM commented on Sep 16, 2022
One more check needs to be added:
def _get_required_interactive_framework(backend_mod): if not hasattr(backend_mod, 'FigureCanvas') or not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"): _api.warn_deprecated( "3.6", name="Support for FigureCanvases without a " "required_interactive_framework attribute") return None # Inline this once the deprecation elapses. return backend_mod.FigureCanvas.required_interactive_frameworkQuLogic commented on Sep 17, 2022
I don't believe the latter check was implemented.
TLCFEM commented on Sep 17, 2022
No, it's not.
HarmvandenBrand commented on Sep 22, 2022
Can confirm this is still an issue with matplotlib 3.6.0 on python 3.10 in PyCharm 2022.2.2
Force matplotlib <3.6.0 to work around matplotlib/matplotlib#23911
Don't require FigureCanvas on backend module more
nfeliccia commented on Sep 27, 2022
Not working on PycharmPro
Error
Traceback (most recent call last): File "F:\gt_stats_iii\scipy_stats_binom_examples.py", line 8, in <module> pizza, marshmallows = plt.subplots(1, 1) File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 1430, in subplots fig = figure(**fig_kw) File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper return func(*args, **kwargs) File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 771, in figure manager = new_figure_manager( File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 346, in new_figure_manager _warn_if_gui_out_of_main_thread() File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 336, in _warn_if_gui_out_of_main_thread if (_get_required_interactive_framework(_get_backend_mod()) and File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 206, in _get_backend_mod switch_backend(dict.__getitem__(rcParams, "backend")) File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 266, in switch_backend canvas_class = backend_mod.FigureCanvas AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'? Process finished with exit code 1FIX: only expect FigureCanvas on backend module if using new style
Don't require FigureCanvas on backend module more
mposter1 commented on Nov 8, 2023
Problem still occurring in PyCharm for me. Still requires FigureCanvas on backend module, running matplotlib 3.8.1. See line 342 of pyplot.py
ksunden commented on Nov 8, 2023
Not having a FigureCanvas class as a backend was deprecated in mpl 3.6 and expired in 3.8, it looks like the most recent versions of PyCharm do have it, so perhaps you need to update?
QuLogic commented on Nov 8, 2023
AFAICT, JetBrains added those values over a year ago, but I cannot tell from the tags exactly what version that means.
mposter1 commented on Nov 9, 2023
Update fixed. Thanks.
benyoung-libenyang commented on Nov 10, 2023
maybe you cloud try.
oukohou commented on Dec 19, 2023
great,this fixed my problem.
FIX: only expect FigureCanvas on backend module if using new style
Don't require FigureCanvas on backend module more