![](/img/trans.png)
[英]How to plot grouped bar chart from two selected columns vs time in python. I shall post my data below
[英]How to remove the decimal numbers from a bar chart in pycharm using python. My code is below
import matplotlib.pyplot as plt
import numpy as np
label = []
numbers = []
times = int(input("How many labels will you have? "))
print("")
for i in range(times):
userlabel = input("What is the name of the label? ")
label.append(userlabel)
print("")
numb = int(input("What is the amount of that label? "))
print("")
numbers.append(numb)
# plotting
y_pos = np.arange(len(label))
plt.bar(y_pos, numbers, align='center', alpha=0.5)
plt.xticks(y_pos, label)
# plt.xlabel(labelname)
# plt.title(title)
plt.show()
x 軸顯示標簽,y 軸顯示值,出於某種原因,這些值也有小數點。
如果您嘗試僅使用 y 軸的 int 值,則可以添加它。
# plotting
y_pos = np.arange(len(label))
plt.bar(y_pos, numbers, align='center', alpha=0.5)
plt.xticks(y_pos, label)
#add
min = 0
max = int(numbers[len(numbers)-1]) + 1
yint=range(min,max)
plt.yticks(yint)
# plt.xlabel(labelname)
# plt.title(title)
plt.show()
將此添加到 xticks 下:
plt.yticks([n for n in range(int(max(numbers))+1)])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.