python - matplotlib bar chart: space out bars -
how increase space between each bar matplotlib barcharts, keep cramming them self centre. (this looks)
import matplotlib.pyplot plt import matplotlib.dates mdates def ww(self):#wrongwords text file open("wrongwords.txt") file: array1 = [] array2 = [] element in file: array1.append(element) x=array1[0] s = x.replace(')(', '),(') #removes quote marks csv file print(s) my_list = ast.literal_eval(s) print(my_list) my_dict = {} 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 replace
plt.bar(range(len(my_dict)), my_dict.values(), align='center')
with
plt.figure(figsize=(20, 3)) # width:20, height:3 plt.bar(range(len(my_dict)), my_dict.values(), align='edge', width=0.3)
Comments
Post a Comment