【发布时间】:2021-08-05 10:31:44
【问题描述】:
我已经花了很长时间在网上寻找解决方案。我用 Matplotlib 创建了一个堆叠的水平条形图。我想增加条之间的空间,但不知道怎么做。
import pandas as pd
import matplotlib.pyplot as plt
d = {
'id': [823,234,213,343,329,289,569,294,295,832],
'dogs': [1,2,3,4,3,5,2,3,4,5],
'cats': [3,4,5,2,1,3,4,5,3,2,],
'birds': [1,4,2,3,4,2,3,1,4,2]}
df = pd.DataFrame(data=d)
df.plot(
x = 'id',
kind = 'barh',
stacked = True,
title = 'Stacked Bar Graph',
mark_right = True,
color=['#D3E0F9','#7AA3F1','#3D68CF'],
width=0.6)
plt.rc('axes', titlesize=6) #fontsize of the title
plt.rc('axes', labelsize=10) #fontsize of the x and y labels
plt.rc('xtick', labelsize=10) #fontsize of the x tick labels
plt.rc('ytick', labelsize=10) #fontsize of the y tick labels
plt.rc('legend', fontsize=10) #fontsize of the legend
【问题讨论】:
-
你试过增加你的身材的宽度/高度吗?
-
我做到了。但我想坚持当前的宽度。但是改变高度不起作用我总是得到错误“barh()为参数'height'获得了多个值”
标签: python matplotlib format bar-chart stacked