python - 如何在 matplotlib.pyplot 中更改我的绘图图的 Y 比例
问题描述
with open('data/covid.csv', encoding="utf8") as file_obj:
file_data = csv.DictReader(file_obj, skipinitialspace = True)
#storing info of dose 1 in dictionary
dicti = {}
for row in file_data:
key = row['State/UTs']
if key in dicti:
dicti[key] = row['Dose 1']
else:
key = row['State/UTs']
dicti[key] = row['Dose 1']
print(dicti)
valuesL = list(dicti.values())
for i in range(0, len(valuesL)):
valuesL[i] = int(valuesL[i])
plt.figure(figsize=(18,12))
ax = plt.bar(list(dicti.keys()),valuesL, color = "green")
plt.xlabel("State/uts", fontsize = 30)
plt.ylabel("Number of people who have taken dose 1", fontsize = 30)
plt.title('States VS people who have taken dose 1', fontsize = 30)
plt.xticks(rotation=80)
for patch in ax.patches:
width = patch.get_width()
height = patch.get_height()
x = patch.get_x()
y = patch.get_y()
plt.text(x , y + height + 4, '{}'.format(height))
plt.show()
这是我的代码,图表显示 y 轴的范围从 0.5 到 1,我希望它根据字典的值进行更改,范围从 10000 到 10000000
解决方案
推荐阅读
- mysql - 如何使用 DBIc Schema deploy() 定义表加载顺序
- sql - 从上一行和当前行中查找相同部门 id 的平均值
- python - 如何打印键是整数的字典元素?
- php - 如何在空表上添加记录
- javascript - 从 Woocommerce 有效负载中提取对象并从字符串中删除反斜杠
- c# - 如何在没有实体框架的情况下以通用方式在 C# 中调用异步存储过程调用
- firebase - 使用螺栓编译器的 hasChild() 问题
- css - “(property)”:(value)”声明中的冒号 (':') 前缺少属性名称。css 全局变量
- c# - await Task.Run 实际上并不等待
- ios - 在ios设备上本地保存json时采取什么方法?