Matplotlib doesn't plot in macos

Question:

I have the following straightforward code:

import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [34, 56, 78, 21]
plt.plot(x, y)
plt.show()

But after changing my MacBook Pro to the M1 chip, I’m getting the following error:

Traceback (most recent call last):
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/main.py", line 291, in <module>
    plt.plot(x, y)
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2728, in plot
    return gca().plot(
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2225, in gca
    return gcf().gca()
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 830, in gcf
    return figure()
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 771, in figure
    manager = new_figure_manager(
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 346, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/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 "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 206, in _get_backend_mod
    switch_backend(dict.__getitem__(rcParams, "backend"))
  File "/Users/freddy/PycharmProjects/TPMetodosNoParametricos/venv/lib/python3.8/site-packages/matplotlib/pyplot.py", line 266, in switch_backend
    canvas_class = backend_mod.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'

do you have any idea about it?

My matplotlib version is 3.6.0

Answers:

i had the same problem today on a different machine in the same matplotlib version. I downgrade to Version 3.5.0 and now it works.

Answered By: bluemchen

yeah, I solved this problem by using pip install matplotlib==3.5.0 and it works now

Answered By: zhou noel

wow thanks for your perfect answer.I was going to run my pycharm code on my remote linux server,i thought the reason of problem is linux without GUI.Finally,i found that i installed wrong version of matplotlib.

Answered By: White
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.