본문 바로가기
파이썬

파이썬 matplotlib 막대 차트 : 공백 막대

by º기록 2020. 10. 26.
반응형


import matplotlib.pyplot as plt
import matplotlib.dates as mdates
def ww(self):#wrongwords text file

    with open("wrongWords.txt") as file:
        array1 = []
        array2 = [] 
        for element in file:
            array1.append(element)

        x=array1[0]
    s = x.replace(')(', '),(') #removes the quote marks from csv file
    print(s)
    my_list = ast.literal_eval(s)
    print(my_list)
    my_dict = {}

    for item in my_list:
        my_dict[item[2]] = my_dict.get(item[2], 0) + 1

    plt.bar(range(len(my_dict)), my_dict.values(), align='center')
    plt.xticks(range(len(my_dict)), my_dict.keys())

    plt.show()

 

해결 방법

 

교체 시도

plt.bar(range(len(my_dict)), my_dict.values(), align='center')

plt.figure(figsize=(20, 3))  # width:20, height:3
plt.bar(range(len(my_dict)), my_dict.values(), align='edge', width=0.3)

 

참조 페이지 https://stackoverflow.com/questions/40575067

 

 

반응형

댓글