Matplotlib in Python reports MatplotlibDeprecationWarning error message when drawing in IDE

Executing Matplotlib in IDEA or Pycharm reports the following error:

MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.
  fig, ax = plt.subplots()

There are two solutions.

Solution 1: specify backend in code

Specify the backend in the code so that the drawn image will not be displayed in the IDE.

The relevant code is as follows:

import matplotlib
import matplotlib.pyplot as plt

# 解决绘图异常问题
matplotlib.use('Qt5Agg')

Here the backend uses "Qt5Agg", which will be directly displayed in a pop-up window when drawing.

Solution 2: Set the Python settings in the IDE

Set the Python settings in the IDE and cancel "Show plots in tool window". At this time, after the session is executed, it will no longer be displayed in the IDE integrated plots, but will be displayed in a pop-up window, which also solves the above warning.
insert image description here
No matter which IDE it is, find a similar option and uncheck it.

Guess you like

Origin blog.csdn.net/wo541075754/article/details/131223431