matplotlib使用小结

1、使用matplotlib提示模块错误

AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?

需要使用

# -*- coding: utf-8 -*-
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

2、显示中文问题解决

# 设置字体为黑体以支持中文显示
matplotlib.rcParams['font.family'] = 'SimHei'
matplotlib.rcParams['axes.unicode_minus'] = False  # 正确显示负号

  

posted @ 2026-01-27 18:11  水凤火凰  阅读(5)  评论(0)    收藏  举报