python。用matplotlib绘柱状图相关问题

给定csv文件,已知第二列为“等级”

要求:用matplotlib画出“等级”列中、不同“等级”的个数的柱状图

即x轴为6种不同“等级”,y轴为各个等级的个数


import matplotlib.pyplot as plt
import pandas as pd
from collections import Counter

plt.rcParams['font.sans-serif'] = 'Microsoft YaHei'
plt.rcParams['axes.unicode_minus'] = False
df=pd.read_excel(r'C:\Users\jackey\Desktop\CSDN/test.xlsx')
c=dict(Counter(df['A'].tolist()))
print(c)
plt.bar(c.keys(), c.values())
plt.show()

可参考我的代码,如果对你有帮助,帮忙采纳下,多谢!

from matplotlib import pyplot as plt

def doAnalysis_areaAvgRent_And_HouseCount():
    areaNameList_x = ['江北','渝北',"九龙坡"]
    areaHouseCountList_y2 = [50,30,25]
    # 画图 柱状图-> 区域 == 房源数量
    plt.figure(figsize=(20, 8), dpi=80)
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False
    plt.bar(areaNameList_x, areaHouseCountList_y2, width=0.3, color="cyan")
    plt.title("各区域房源数量柱状图", fontsize=24)
    plt.ylabel("房源数量(套)", fontsize=16)
    plt.xlabel("区域名字", fontsize=16)
    plt.grid()
    plt.show()
doAnalysis_areaAvgRent_And_HouseCount()

有帮助请点击右上角的采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力
绘制直方图,你直接将数据按照areaNameList_x,areaHouseCountList_y2的格式写入函数即可绘制

img

img