为什么所有的传说都没有出现在我的情节里?

2024-04-26 18:19:36 发布

您现在位置: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()

It is not showing other legends other than contract

帮帮我!


Tags: importtypecountnppltmathcustomeritem
2条回答

您可以在条形图上迭代以访问每个条形图:

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)

example_plot

你会发现legend doc很有用

我个人会使用for循环分别绘制每个条来处理这个问题。可能还有其他直接的方法。我用测试数据来提供答案。你知道吗

# imports 
m = [10, 20, 13, 15, 18, 5, 7]
Categories = ('CO','IT','CU','RE','AC','IN','Other')
labels =['Contract','ITEM','CUSTOMER','REQUEST','ACCOUNT','INQUIRY','OTHER']
colors = ['black', 'red', 'green', 'blue', 'orange','purple','brown']

for j in range(len(m)):
    plt.bar(j, m[j], width=0.5,align='center', colors = color[j], label=labels[j])

plt.xticks(np.arange(len(m)), Categories)
plt.legend(loc=1)

输出

enter image description here

相关问题 更多 >