首页 > 解决方案 > Matplot Lib 图形在左侧被截断,标签未显示

问题描述

我的水平条形图的标签在 matplot lib 中被截断。我怀疑这是因为我做了一些标签重新分配。但我不确定。有没有办法强制图像更大/向左延伸,所以它不会被截断?我在下面添加了我的代码以了解我的意思。

df_1 = df_1.astype({"Education": 'str', "Count": 'int64'}) #Converting the first column from float to string
print(df_1.dtypes) #Check the types
df_1.at[0,'Education'] = "High School" #Reassign the labels to what they actually mean
df_1.at[1,'Education'] = "Trade School"
df_1.at[2,'Education'] = "Bachelor's Degree"
df_1.at[3,'Education'] = "Graduate Degree"

print(df_1)

df_1.plot.barh(x='Education', y='Count', title='Hope this works', color='blue', stacked=True)

这是我得到的图像。

这是我得到的图像。 抱歉,如果这不是足够的信息,这是我第一次发布。

标签: python-3.xpandasimagematplotlibgraph

解决方案


推荐阅读