python - 为什么我的情节中没有显示所有图例?
问题描述
def category_count(x):
return sum(Elig_Subject_line['ELIGIBILITY TYPE'].str.count(x))
Cat_Count = map(lambda x: category_count(x),
['CONTRACT','ITEM','CUSTOMER','REQUEST',
'ACCOUNT','INQUIRY','Other'])
[a,b,c,d,e,f,g] = list(Cat_Count)
m = [a,b,c,d,e,f,g]
import numpy as np
import matplotlib.pyplot as plt
import math
Categories = ('CO','IT','CU','RE','AC','IN','Other')
# high = max(m)
# low = min(m)
plt.bar(np.arange(len(m)),m,width =0.5,align ='center',color = ['black',
'red', 'green', 'blue', 'orange','purple',
'brown'])
plt.xticks(np.arange(len(m)), Categories)
#plt.ylim([math.ceil(low-0.5*(high-low)), math.ceil(high+0.5*(high-low))])
plt.ylabel('Volume of Items Types')
plt.title('Count of ELIGIBILITY TYPE')
label =['Contract','ITEM','CUSTOMER','REQUEST','ACCOUNT','INQUIRY','OTHER']
#plt.legend(m,label)
plt.legend(label,loc=1)
#plt.figure(figsize =(4,5))
plt.savefig(r'D:\Users\7031\Documents\Mounika\Eligibility
Type.JPEG',dpi=400,orientation='landscape',figsize =(5,5))
plt.show()
帮帮我!
解决方案
You can iterate over the bar plot to access each bar:
label =['Contract','ITEM','CUSTOMER','REQUEST','ACCOUNT','INQUIRY','OTHER']
bar_plot = plt.bar(range(7), range(7, 0, -1), color = ['black', 'red', 'green', 'blue',
'orange','purple', 'brown'])
plt.legend([bar for bar in bar_plot], label)
You can find the legend doc useful
推荐阅读
- android - 如何使用 TextureView 显示部分视频?
- neural-network - 修剪 Keras 前馈网络的输出
- sql - 如何在 OBIEE 11g 数据模型中有效地“外连接”两个数据源(SQL 查询)?
- angular - 调用方法 createUserWithEmailAndPassword 而不进行登录
- javascript - 使用此关键字时,为什么在调试和运行时会输出不同的结果?
- c# - 如何为 VSCode 调试适配器制作单元测试用例?
- java - 如何将失败的消息从我的 Web / 应用程序服务器 (java) 重新传输到 FCM 服务器
- matlab - 40x455 大矩阵的平均值(来自 5 个会话的数据,即每个会话 40x91)
- javascript - 单击以在弹出窗口中显示特定用户的记录
- c++ - 在编译时将强类型枚举器转换为其基础类型?