- 运行报错:AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'
| |
| |
| pip show matplotlib |
| |
| pip uninstall matplotlib |
| |
| pip install matplotlib==3.5.0 |
| import pandas as pd |
| import matplotlib.pyplot as plt |
| import numpy as np |
| |
| |
| plt.rcParams['font.sans-serif'] = ['SimHei'] |
| |
| plt.rcParams['axes.unicode_minus'] = False |
| |
| plt.figure(figsize=(11, 8)) |
| |
| path = r"C:\work\python\matplotlib_files\01.柱状图.xlsx" |
| data = pd.read_excel(path) |
| print(data) |
| |
| |
| data.sort_values('分数', inplace=True, ascending=False) |
| |
| plt.bar(data.姓名, data.分数) |
| plt.show() |
| |
| |
| plt.bar(x=data.姓名, height=data.分数, color="red", alpha=0.5, label='分数') |
| |
| plt.legend() |
| |
| plt.xlabel('姓名', fontsize=20) |
| plt.ylabel('分数') |
| |
| plt.xticks(rotation=45) |
| |
| |
| |
| plt.title("成绩展示", fontsize=20) |
| |
| plt.ylim(0, 120) |
| |
| for x, y in enumerate(data.分数): |
| plt.text(x, y, str(y), fontsize=20, va='bottom', ha='center', color='b') |
| |
| |
| |
| plt.show() |
点击查看详情

| path = r"C:\work\python\matplotlib_files\01.柱状图.xlsx" |
| data = pd.read_excel(path) |
| print(data) |
| |
| |
| data.sort_values('分数', inplace=True, ascending=True) |
| |
| plt.bar(x=0, bottom=data.姓名, height=0.5, width=data.分数, orientation='horizontal') |
| |
| plt.title('班级成绩排名', fontsize=20) |
| |
| plt.xlim(0, 120) |
| plt.show() |
点击查看详情

| path = r"C:\work\python\matplotlib_files\03.分组柱状图.xlsx" |
| data = pd.read_excel(path) |
| print(data) |
| |
| |
| b = np.arange(len(data.姓名)) |
| w = 0.4 |
| |
| plt.bar(x=b, height=data.第一年, width=w, label='第一年') |
| plt.bar(x=b+w, height=data.第二年, width=w, label='第二年') |
| |
| plt.xticks(b, data.姓名, rotation=45) |
| |
| plt.legend() |
| |
| plt.xlabel('姓名') |
| |
| plt.ylim(0, 120) |
| |
| plt.gcf().subplots_adjust(bottom=0.3) |
| |
| for x, y in enumerate(data.第一年): |
| |
| plt.text(x, y+1, str(y), ha='center') |
| |
| for x, y in enumerate(data.第二年): |
| |
| plt.text(x+w, y+1, str(y), ha='center') |
| plt.show() |
点击查看详情

| path = r"C:\work\python\matplotlib_files\04.堆叠柱状图.xlsx" |
| data = pd.read_excel(path) |
| print(data) |
| |
| plt.bar(x=data.姓名, height=data.语文, width=0.8, bottom=0, label='语文') |
| plt.bar(x=data.姓名, height=data.数学, width=0.8, bottom=data.语文, label='数学') |
| plt.bar(x=data.姓名, height=data.英语, width=0.8, bottom=data.语文+data.数学, label='英语') |
| |
| plt.legend(loc='upper center', ncol=3) |
| |
| plt.grid(axis='y') |
| |
| for x, y in enumerate(data.语文): |
| |
| plt.text(x, y, str(y), va='top') |
| |
| for a1, a2, a3 in zip(data.姓名, data.语文, data.数学): |
| plt.text(a1, a2+a3, str(a3), va='top') |
| |
| for a1, a2, a3, a4 in zip(data.姓名, data.语文, data.数学, data.英语): |
| plt.text(a1, a2+a3+a4, str(a4), va='top') |
| plt.show() |
| |
点击查看详情

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?