条形图
条形图用于将按类别组织的数据可视化为一系列条形,每个条形的高度表示该类别的数据值。
在本练习中,您将可视化提供的 medals DataFrame 中各国获得的金牌数。该 DataFrame 以各国家为索引,并包含名为 "Gold" 的列,按行给出每个国家获得的金牌数量。
本练习是课程的一部分
Matplotlib 数据可视化入门
练习说明
- 调用
ax.bar方法,将国家作为自变量绘制"Gold"列。 - 使用
ax.set_xticklabels将 x 轴刻度标签设置为国家名称。 - 在调用
ax.set_xticklabels时,通过rotation关键字参数将 x 轴刻度标签旋转 90 度。 - 将 y 轴标签设置为
"Number of medals"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
fig, ax = plt.subplots()
# Plot a bar-chart of gold medals as a function of country
____
# Set the x-axis tick labels to the country names
____.set_xticklabels(____, ____)
# Set the y-axis label
____
plt.show()