python绘制单列堆积柱形图

一、代码

import matplotlib.pyplot as plt
import numpy as np

# 数据设定
N = 10
menMeans = (20, 35,20, 35,20, 35,20, 35,20, 35)
womenMeans = (25, 32,25, 32,25, 32,25, 32,25, 32)


# 绘制堆积柱状图
ind = np.arange(N)  
width = 0.35       

#创建图形和子图
fig, ax = plt.subplots()

p1 = ax.bar(ind, menMeans, width)
p2 = ax.bar(ind, womenMeans, width, bottom=menMeans)

ax.axhline(0, color='grey', linewidth=0.8)
ax.set_ylabel('数量',fontproperties=zhfont)
ax.set_title('干净标签和噪声标签的样本数量',fontproperties=zhfont)
ax.set_xticks(ind)
ax.set_xticklabels(('类别1', '类别2','类别3','类别4','类别5','类别6','类别7','类别8','类别9','类别10'),fontproperties=zhfont)

ax.legend((p1[0], p2[0]), ('TP:干净标签', 'NP:噪声标签'),prop=zhfont)

# 显示图形
plt.show()

二、结果

相关推荐

  1. 时间趋势可视化- Python

    2024-03-18 04:20:02       40 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-18 04:20:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-18 04:20:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-18 04:20:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-18 04:20:02       20 阅读

热门阅读

  1. 客户端渲染与服务端渲染

    2024-03-18 04:20:02       22 阅读
  2. 深入了解Android垃圾回收机制

    2024-03-18 04:20:02       27 阅读
  3. 从零开始的LeetCode刷题日记:541. 反转字符串II

    2024-03-18 04:20:02       23 阅读
  4. 如何解决接口幂等的问题?

    2024-03-18 04:20:02       25 阅读
  5. SpringSecurity

    2024-03-18 04:20:02       20 阅读
  6. Docker 新建网络实现容器间通信

    2024-03-18 04:20:02       20 阅读