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

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

當(dāng)“整潔的數(shù)據(jù)”不是問(wèn)題時(shí),如何在plotnine中為多條曲線添加圖例

當(dāng)“整潔的數(shù)據(jù)”不是問(wèn)題時(shí),如何在plotnine中為多條曲線添加圖例

郎朗坤 2023-09-19 14:02:17
有幾個(gè)人詢問(wèn),當(dāng)曲線因選擇要繪制的行而不同時(shí),如何在多條曲線中添加圖例ggplot2或?yàn)槎鄺l曲線添加圖例。plotnine典型的答案是將數(shù)據(jù)重新格式化為整齊的數(shù)據(jù)。一些示例位于此處、此處和此處。我需要多行不是因?yàn)閷?duì)數(shù)據(jù)進(jìn)行子集化,而是因?yàn)槲蚁氡容^平滑方法。所有線路的數(shù)據(jù)都相同,因此上述答案沒(méi)有幫助。后兩個(gè)答案指出,在R 中,可以通過(guò)將說(shuō)明符移動(dòng)到內(nèi)部ggplot2來(lái)創(chuàng)建圖例。這里詳細(xì)描述了這一點(diǎn),這與我想要做的類似。coloraes(...)這也應(yīng)該起作用plotnine嗎?我嘗試了一個(gè)類似于上一個(gè)鏈接的示例。沒(méi)有圖例它工作正常:from plotnine import *from plotnine.data import *(ggplot(faithful, aes(x='waiting'))    + geom_line(stat='density', adjust=0.5, color='red')    + geom_line(stat='density', color='blue')    + geom_line(stat='density', adjust=2, color='green')    + labs(title='Effect of varying KDE smoothing parameter',           x='Time to next eruption (min)',           y='Density'))但當(dāng)我為了獲得傳奇color而進(jìn)入時(shí),它失敗了:aesfrom plotnine import *from plotnine.data import *(ggplot(faithful, aes(x='waiting'))    + geom_line(aes(color='red'), stat='density', adjust=0.5)    + geom_line(aes(color='blue'), stat='density')    + geom_line(aes(color='green'), stat='density', adjust=2)    + labs(title='Effect of varying KDE smoothing parameter',           x='Time to next eruption (min)',           y='Density')    + scale_color_identity(guide='legend'))這給出了錯(cuò)誤 PlotnineError: "Could not evaluate the 'color' mapping: 'red' (original error: name 'red' is not defined)"。關(guān)于如何添加圖例有什么建議嗎?謝謝。
查看完整描述

2 回答

?
白豬掌柜的

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

看起來(lái)您發(fā)布的最后一個(gè)鏈接是在正確的軌道上,但您必須欺騙 python 來(lái)克服 R 所做的一些非標(biāo)準(zhǔn)評(píng)估。我可以通過(guò)在顏色名稱周圍設(shè)置兩組引號(hào)來(lái)使其工作:


(ggplot(faithful, aes(x='waiting'))

? ? + geom_line(aes(color="'red'"), stat='density', adjust=0.5)

? ? + geom_line(aes(color="'blue'"), stat='density')

? ? + geom_line(aes(color="'green'"), stat='density', adjust=2)

? ? + labs(title='Effect of ...',

? ? ? ? ? ?x='Time to next eruption (min)',

? ? ? ? ? ?y='Density')

? ? + scale_color_identity(guide='legend',name='My color legend')

)

1

您可以制作自己的標(biāo)簽,例如帖子:


(ggplot(faithful,aes(x='waiting'))

?+ geom_line(aes(color="'red'"),stat='density',adjust=.5)

?+ geom_line(aes(color="'blue'"),stat='density')

?+ geom_line(aes(color="'green'"), stat='density',adjust=2)

?+labs(title='Effect of ...',x='Time to next eruption (min)',

? ? ? ?y='Density')

?+ scale_color_identity(guide='legend',name='My colors',

? ? ? ? ? ? ? ? ? ? ? ? breaks=['red','blue','green'],

? ? ? ? ? ? ? ? ? ? ? ? labels=['Label 1','Label 2','Label 3']))

2


查看完整回答
反對(duì) 回復(fù) 2023-09-19
?
FFIVE

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

將顏色放在引號(hào)中,例如'"red"'而不是'red'。


(ggplot(faithful, aes(x='waiting'))

    + geom_line(aes(color='"red"'), stat='density', adjust=0.5)

    + geom_line(aes(color='"blue"'), stat='density')

    + geom_line(aes(color='"green"'), stat='density', adjust=2)

    + labs(title='Effect of varying KDE smoothing parameter',

           x='Time to next eruption (min)',

           y='Density')

    + scale_color_identity(guide='legend')

)


查看完整回答
反對(duì) 回復(fù) 2023-09-19
  • 2 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報(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)