0
我有下面的代码创建两个条形图...x轴unorder matplotlib海之境
f, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 6), sharex=False,)
# Generate some sequential data
x1 = edu_count['Education']
y1 = edu_count['Frequency']
edu_order = ['0', '1.0', '2.0', '3.0', '4.0', '5.0', '6.0', '7.0', '8.0', '9.0', '10.0', '11.0', '12.0', '13.0', '14.0', '15.0', '16.0', '17.0']
sns.barplot(x1, y1, color='b', ax=ax1)
ax1.set_title('2003 All Death By Education Level')
ax1.set_ylabel("Frequency")
ax1.set_xlabel('Education Level')
# Center the data to make it diverging
x2 = suicide_data['Education']
y2 = suicide_data['Frequency']
sns.barplot(x2, y2, color='b', ax=ax2)
ax2.set_title('2003 Suicide Death By Education Level')
ax2.set_ylabel("Frequency")
ax2.set_xlabel('Education Level')
# Finalize the plot
sns.despine(bottom=True)
plt.tight_layout(h_pad=2)
我遇到的问题是,该地块即将升序排序。
我所需要的x轴,以便从0到17从左到右代替。我试图使用order=
参数并传递上面设置的变量,但这不起作用。有谁知道如何禁用排序行为的y轴的值?
我在Jupyter笔记本电脑这样做,OS X埃尔卡皮坦Python3
为什么你将数字编码为字符串?当你给seaborn号码时,它会把它们按正确的顺序排列。 –
因为原始的csv不干净。我不得不做一些数据处理来达到期望的阶段。 – Gilbert