5

I create a pandas scatter-matrix usng the following code:

import numpy as np
import pandas as pd

a = np.random.normal(1, 3, 100)
b = np.random.normal(3, 1, 100)
c = np.random.normal(2, 2, 100)

df = pd.DataFrame({'A':a,'B':b,'C':c})
pd.scatter_matrix(df, diagonal='kde')

This result in the following scatter-matrix: enter image description here

The first row has no ytick labels, the 3th column no xtick labels, the 3th item 'C' is not labeled.

Any idea how to complete this plot with the missing labels ?

4

2 に答える 2

5

問題のサブプロットにアクセスし、そのように設定を変更します。

axes = pd.scatter_matrix(df, diagonal='kde')
ax = axes[2, 2] # your bottom-right subplot
ax.xaxis.set_visible(True)
draw()

以下のリンクで、scatter_matrix関数がどのようにラベル付けを行うかを調べることができます。これを何度も繰り返していることに気付いた場合は、コードをファイルにコピーして、独自のカスタムscatter_matrix関数を作成することを検討してください。

https://github.com/pydata/pandas/blob/master/pandas/tools/plating.py#L160

拒否されたコメントに応じて編集します。

これの明らかな拡張、実行ax[0, 0].xaxis.set_visible(True)などは機能しません。何らかの理由で、scatter_matrixはaxes [2、2]に目盛りとラベルを表示せずに設定しているように見えますが、残りの部分には目盛りとラベルを設定していません。他のサブプロットに目盛りとラベルを表示する必要があると判断した場合は、上記のリンク先のコードをさらに深く掘り下げる必要があります。

具体的には、ifステートメントの条件を次のように変更します。

if i == 0
if i == n-1
if j == 0
if j == n-1

それぞれ。私はそれをテストしていませんが、それでうまくいくと思います。

于 2013-01-24T23:09:21.387 に答える
1

上記で返信できないため、Google で検索するための変更されていないソース コード バージョンは次のとおりです。

n = len(features)

for x in range(n):
    for y in range(n):
        sax = axes[x, y]
        if ((x%2)==0) and (y==0):
            if not sax.get_ylabel():
                sax.set_ylabel(features[-1])       
            sax.yaxis.set_visible(True)

        if (x==(n-1)) and ((y%2)==0):
            sax.xaxis.set_visible(True)

        if ((x%2)==1) and (y==(n-1)):
            if not sax.get_ylabel():
                sax.set_ylabel(features[-1])       
            sax.yaxis.set_visible(True)

        if (x==0) and ((y%2)==1):
            sax.xaxis.set_visible(True)

features は列名のリストです

于 2013-09-25T00:35:02.743 に答える