python - 如何使该图的 y 轴从零开始?
问题描述
url = "https://www.worldometers.info/coronavirus/"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data, "html.parser")
'''Since there are no unary operators supported between 'counter' and the variable 'i',
I must declare another variable 'counter' and set it equal to zero, with the value
of counter being updated by 1 each time.'''
total_cases = []
counter = 0;
global_case_information = soup.find_all("div", {"class":"maincounter-number"})
for cases in global_case_information:
if(counter == 13):
break
else:
total_cases.append(cases.text)
counter += 1
global_cases = {"Total Deaths":total_cases[1], "Total Recovered":total_cases[2]}
covid_figure = plt.figure()
plt.rcParams["figure.figsize"] = [40, 40]
keys_array = np.arange(len(global_cases.keys()))
axes = plt.gca()
plt.xticks(keys_array, global_cases.keys())
plt.ylabel("Number Of People Affected(Globally)")
plt.title("Global Covid-19 Statistics")
plt.bar(keys_array, global_cases.values())
plt.show()
好的,所以我试图让 y 轴从零开始,并且相对偏移量为 50000 个单位。但是,事实并非如此,我什至尝试执行以下操作:
plt.yticks(np.arange(0, 300000, 50000))
但这行不通。
解决方案
请在 plt.show() 之前设置以下命令
plt.set_ylim(ymin=0)
我希望你问这个。请告诉我。
推荐阅读
- php - 在 Woocommerce 中根据购物车商品数量添加自定义结帐字段
- php - 请求实体太大 - 413 错误 IPS 4.3.4
- macos - Jenkins Blue Ocean ./gradlew:没有这样的文件或目录
- swift - 使用单例模式在 Swift 中创建管理器的最佳方法
- angular - 如何在 Angular CLI 应用程序中禁用 CSS 中的 URL 解析
- python - 多次匹配后合并 Pandas 数据框
- html - 如何显示 Illustrator 生成的 CSS 渐变?
- c# - 转换为通用接口
- java - 石英作业等到启动并在完成后待机
- aws-lambda - 有时来自 lambda 函数的连接超时