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

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

如何在 Pandas 中繪制和標記多個自相關(guān)函數(shù)?

如何在 Pandas 中繪制和標記多個自相關(guān)函數(shù)?

牛魔王的故事 2022-06-14 17:16:02
我有幾個變量,我想在一張圖上查看它們的自相關(guān)函數(shù)。我可以做這個。但問題是我不確定如何創(chuàng)建一個圖例,以便我知道哪個變量是哪個。這是我的數(shù)據(jù)的樣子:import pandas as pd from pandas.plotting import autocorrelation_plotdf = pd.DataFrame(data = {    "Year": [y for y in range(1800, 2000)],    "Var 1": [random.random() for i in range(200)],     "Var 2": [random.random() for i in range(200)],     "Var 3": [random.random() for i in range(200)]})df.set_index("Year")現(xiàn)在這是我在一張圖上繪制自相關(guān)函數(shù)的方法:for variable in df.columns:    autocorrelation_plot(df[variable])問題是沒有傳說,所以我不知道哪個變量是哪個。而且,autocorrelation_plot沒有l(wèi)egend論據(jù)。
查看完整描述

3 回答

?
函數(shù)式編程

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

我添加了一個標簽變量來獲取標簽:

for variable in df.columns:
   ax = autocorrelation_plot(df[variable], label = variable)

股票數(shù)據(jù)

它奏效了


查看完整回答
反對 回復(fù) 2022-06-14
?
慕尼黑的夜晚無繁華

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

試試這個代碼:


for variable in df.columns:

    ax = autocorrelation_plot(df[variable])


ax.legend(ax.get_lines())

autocorrelation_plot返回一個類型的對象,AxesSubplot它允許您像使用 matplotlib 一樣操作圖形。因此,要添加圖例,您只需將函數(shù)剛剛繪制的線條作為參數(shù)傳遞。


例如,使用此代碼,我打印每條打印行的顏色,然后更改行的標簽,添加字符串variable:


i=0

for variable in df.columns:

    ax = autocorrelation_plot(df[variable])


    print(variable, ax.get_lines()[-1].get_color())


    for k in range(i, len(ax.get_lines())):

        ax.get_lines()[k].set_label(f'{k}_{variable}')

    i+=6


ax.legend(ax.get_lines())


查看完整回答
反對 回復(fù) 2022-06-14
?
守候你守候我

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

我即興創(chuàng)作了來自@Massifox 的答案,我能夠為自相關(guān)圖定制一個圖例


from matplotlib.lines import Line2D

plot_color = []

for variable in df.columns:

    ax = autocorrelation_plot(df[variable])

    plot_color.append((ax.get_lines()[-1].get_color()))


custom_lines = [Line2D([0],[0], color=plot_color [0], lw=2),

                Line2D([0],[0], color=plot_color [1], lw=2),

                Line2D([0],[0], color=plot_color [2], lw=2)]

                

ax.legend(custom_lines, ['label1', 'label2', 'label3'])

http://img1.sycdn.imooc.com//62a852000001f20d05620419.jpg

查看完整回答
反對 回復(fù) 2022-06-14
  • 3 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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