我如何用matplotlib条形图来增加每个条形图之间的空间,因为它们不断地把自己塞进中心.enter image description here(这是它目前的样子)

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()

推荐答案

try 替换

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)

Python-3.x相关问答推荐

正则表达式匹配并提取括号前的单词

确定字符串的长度并提取前15或14个字符

Paramiko SFTPClient get()和put()函数的通过/失败结果?

Numba编译时间呈指数级增长--可以像C编译器一样配置优化级别吗?

如何将参数/值从测试方法传递给pytest的fixture函数?

如何将python点击参数设置为与选项回调不同的参数的别名?

将两列的乘积连续添加到一列的累积和中

链接列未延伸到数据框的末尾

替换 .txt 文件中的项目列表

通过 Pandas 通过用户定义函数重命名数据框列

为什么不能用格式字符串 '-' 绘制点?

如何在 Python 中 cv2 的窗口标题上动态更新 FPS

如何使用 regex sub 根据列表中的变量替换字符

ImportError:无法从jinja2导入名称escape

如何从 Python 3.5 降级到 Python 3.4

无法在 Windows Python 3.5 上安装 Levenshtein 距离包

pysftp vs. Paramiko

如何用pymongo连接远程mongodb

无法在 Windows 8 中使用 Python 3.3 找到 vcvarsall.bat

TypeError:只有整数标量数组可以转换为标量索引