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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在seaborn的“嶺圖”處向軸標(biāo)簽添加單位

如何在seaborn的“嶺圖”處向軸標(biāo)簽添加單位

翻閱古今 2021-10-12 15:27:59
我想根據(jù) seaborn 'ridge plot' 示例(https://seaborn.pydata.org/examples/kde_ridgeplot.html)執(zhí)行以下操作:我想將單位添加到 x 軸的 x 標(biāo)簽中,使其在圖中顯示為[m]中的x。我怎么做?將命令擴(kuò)展g.map(label, "x")為g.map(label, "x in [m]")導(dǎo)致以下錯(cuò)誤:KeyError: "['x [m]'] not in index"我的代碼如下:import numpy as npimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltsns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})errorNames = ['Error 1 - abc.....',              'Error 2 - abc.....',              'Error 3 - abc.....',              'Error 4 - abc.....',              'Error 5 - abc.....',              'Error 6 - abc.....',              'Error 7 - abc.....',              'Error 8 - abc.....',              'Error 9 - abc.....',              'Error 10 - abc.....',              'Error 11 - abc.....',              'Error 12 - abc.....',              'Error 13 - abc.....']# Create the datars = np.random.RandomState(1979)x = rs.randn(650)#g = np.tile(list("ABCDEFGHIJKLM"), 50)g = np.tile(list(errorNames), 50)df = pd.DataFrame(dict(x=x, g=g))#m = df.g.map(ord)#df["x"] += m# Initialize the FacetGrid objectpal = sns.cubehelix_palette(10, rot=-.25, light=.7)g = sns.FacetGrid(df, row="g", hue="g", aspect=15, height=.5, palette=pal)# Draw the densities in a few stepsg.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2)g.map(plt.axhline, y=0, lw=2, clip_on=False)#sns.plt.xlim(-10, 3)# Define and use a simple function to label the plot in axes coordinatesdef label(x, color, label):    ax = plt.gca()    ax.text(0, .2, label, fontweight="bold", color=color,            ha="left", va="center", transform=ax.transAxes)g.map(label, "x")#g.map(label, "x [m]")# Set the subplots to overlap # Erst hier wird geplottedg.fig.subplots_adjust(hspace=-.25)# Remove axes details that don't play well with overlapg.set_titles("")g.set(yticks=[])g.despine(bottom=True, left=True)
查看完整描述

3 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

一種方法是使用g.axes. 然后獲取數(shù)組中的最后一個(gè)軸并設(shè)置該軸的 xlabel:


last_ax = g.axes.flat[-1]

last_ax.set_xlabel("x in [m]")

http://img1.sycdn.imooc.com//6165394b0001168006480474.jpg

查看完整回答
反對(duì) 回復(fù) 2021-10-12
?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

只是一個(gè)附加說(shuō)明,您可能希望將 pal 中的數(shù)量增加到 13 以保持顏色漸變。

pal = sns.cubehelix_palette(13, rot=-.25, light=.7)


查看完整回答
反對(duì) 回復(fù) 2021-10-12
?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊

只是玩弄軸對(duì)象g,我找到了一種簡(jiǎn)單且看似直接的方法來(lái)使用set_xlabels. 在這里閱讀文檔,感謝@DavidG 找到它。具體來(lái)說(shuō),


set_xlabels([label]) 在網(wǎng)格的底行標(biāo)記 x 軸。


g.map(label, "x")

g.set_xlabels('x in [m]')

http://img1.sycdn.imooc.com//6165393d0001d99405260455.jpg

查看完整回答
反對(duì) 回復(fù) 2021-10-12
  • 3 回答
  • 0 關(guān)注
  • 325 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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