這很奇怪。旋轉(zhuǎn) -90o 時,所有標(biāo)簽均等距顯示并位于其位置:feat_names = ["totalUniqueCustomerPhoneNumberLocal_f", "userIdentitty_f", "EMAIL_WEEKS_1_f", "length_f", "totalValidations_f", "amount_per_purchase_k", "amount_f"]X1 = np.array([0.18790969, 0.18208303, 0.15003641, 0.11143482, 0.07428987, 0.06846322, 0.06773489])plt.figure()plt.title("Feature importances")plt.bar(range(X1.shape[0]), X1,color="r", align="center")plt.xticks(range(X1.shape[0]), feat_names, rotation = -90)plt.xlim([-1, X1.shape[0]])plt.show()但是,我需要它們旋轉(zhuǎn) -45o,這就是發(fā)生的情況:feat_names = ["totalUniqueCustomerPhoneNumberLocal_f", "userIdentitty_f", "EMAIL_WEEKS_1_f", "length_f", "totalValidations_f", "amount_per_purchase_k", "amount_f"]X1 = np.array([0.18790969, 0.18208303, 0.15003641, 0.11143482, 0.07428987, 0.06846322, 0.06773489])plt.figure()plt.title("Feature importances")plt.bar(range(X1.shape[0]), X1,color="r", align="center")plt.xticks(range(X1.shape[0]), feat_names, rotation = -45)plt.xlim([-1, X1.shape[0]])plt.show()關(guān)于如何使標(biāo)簽在旋轉(zhuǎn) -45o 時開始與條形中心對齊的任何想法?
1 回答

慕俠2389804
TA貢獻(xiàn)1719條經(jīng)驗 獲得超6個贊
水平對齊通過horizontalalignment
或其別名完成ha
,
plt.xticks(..., rotation = -45, ha="left")
添加回答
舉報
0/150
提交
取消