小编Smi*_*ith的帖子

matplotlib条形图:空间栏

如何使用matplotlib条形图增加每个条形图之间的空间,因为它们会将它们自我填充到中心.在此输入图像描述 (这是它目前的样子)

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()
Run Code Online (Sandbox Code Playgroud)

python matplotlib python-3.x

18
推荐指数
2
解决办法
3万
查看次数

标签 统计

matplotlib ×1

python ×1

python-3.x ×1