大熊猫3x3散射矩阵缺少标签

ron*_*ydw 5 python matplotlib pandas

我使用以下代码创建一个pandas scatter-matrix:

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')
Run Code Online (Sandbox Code Playgroud)

这导致以下散布矩阵: 在此输入图像描述

第一行没有ytick标签,第3行没有xtick标签,第3项"C"没有标记.

知道如何用缺少的标签完成这个情节吗?

Dan*_*lan 5

访问有问题的子图并更改其设置.

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

您可以在下面的链接中检查scatter_matrix函数的标记方式.如果您发现自己一遍又一遍地这样做,请考虑将代码复制到文件中并创建自己的自定义scatter_matrix函数.

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

编辑,以回应被拒绝的评论:

这种明显的扩展,做ax[0, 0].xaxis.set_visible(True)等等都行不通.出于某种原因,scatter_matrix似乎为轴[2,2]设置了刻度和标签而没有使它们可见,但它没有为其余部分设置刻度和标签.如果您认为有必要在其他子图上显示刻度和标签,则必须深入研究上面链接的代码.

具体来说,将if语句的条件更改为:

if i == 0
if i == n-1
if j == 0
if j == n-1
Run Code Online (Sandbox Code Playgroud)

分别.我没有测试过,但我认为它会起作用.