我想要像照片上那样的东西
这是我的密码:
import matplotlib.pyplot as plt
import pandas as pd
plt.style.use('seaborn-notebook')
data = {
'Unmarried woman': [36, 23, 28, 20, 16],
'Married woman': [26, 38, 49, 14, 38]
}
unmarried_labels = ['30–55', '14–50', '16-59', '16-24', '13-26']
married_labels = ['25–50', '29–59', '34–89', '11–18', '33–55']
df = pd.DataFrame(data, columns=['Unmarried woman', 'Married woman'],
index=['Africa', 'Asia', 'Latin America', 'Northern America',
'Europe'])
df.plot.barh()
plt.title(
'Abortion rate per 1000 women aged 15–44 y. by marital status (2010–2014)',
fontweight='bold', fontsize=11)
plt.show()
从Matplotlib 3.4.0开始,这可以通过^{} 和带标签的压缩容器来实现:
all_labels
中的第一个列表将与列0(Unmarried woman
)对齐,并在列之间继续labels
)中的索引0将与数据帧中的索引0对齐,即Africa
,并继续向下移动行李>总而言之:
相关问题 更多 >
编程相关推荐