第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Seaborn 圖未顯示在軸上

Seaborn 圖未顯示在軸上

UYOU 2021-06-13 15:10:46
我有一個如下所示的 Pandas DataFrame:counts = pd.DataFrame({'Pair A': {8: 4, 9: 1, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0}, 'Pair B': {8: 4, 9: 2, 10: 1, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0}, 'Pair C': {8: 3, 9: 2, 10: 1, 11: 1, 12: 1, 13: 1, 14: 1, 15: 1}, 'Pair D': {8: 2, 9: 1, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0}})我只是使用以下代碼使用 DataFrame 的一部分創(chuàng)建一個簡單的圖:plt.figure()sns.set_palette("pastel")temp = pd.DataFrame(counts).drop([0,1,2,3,4,5,6], axis='index')temp.index = temp.index + 1temp.plot()sns.set_style('ticks')plt.ylabel('title')plt.xlabel('xlabel')plt.title('title')plt.xticks(range(len(temp.index)), temp.index, rotation=45)plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))sns.despine(offset=10, trim=True)plt.xticks(rotation=45)但它會產(chǎn)生如下所示的圖像:如何將繪圖居中在 x 軸上?
查看完整描述

2 回答

?
紫衣仙女

TA貢獻1839條經(jīng)驗 獲得超15個贊

這似乎是:

plt.xticks(range(len(temp.index)), temp.index, rotation=45)

導(dǎo)致問題,如果替換為:

plt.xticks(temp.index, temp.index, rotation=45)

一切都按預(yù)期工作。


查看完整回答
反對 回復(fù) 2021-06-15
?
精慕HU

TA貢獻1845條經(jīng)驗 獲得超8個贊

當(dāng)您調(diào)用plt.xticks, 并提供 2 個位置參數(shù)時,第一個參數(shù)變?yōu)?code>locs標簽將出現(xiàn)的 x 值,第二個變?yōu)?code>labels刻度標簽值。因此,plt.xticks(range(len(temp.index)), temp.index, rotation=45)您在位置 0、1、2、3.... 處繪制 x 刻度標簽,而您的數(shù)據(jù)在不同的范圍內(nèi)(8、9、10....)。

因此,如果您想自定義標簽,您可以更改label部分,例如plt.xticks(temp.index, ['x%s'% v for v in temp.index], rotation=45).


查看完整回答
反對 回復(fù) 2021-06-15
  • 2 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號