pandas 3x3散布矩阵缺失标签 [英] pandas 3x3 scatter-matrix missing labels

查看:74
本文介绍了 pandas 3x3散布矩阵缺失标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码创建一个熊猫分散矩阵:

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:

第一行没有ytick标签,第三列没有xtick标签,第三项目'C'没有标签.

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 ?

推荐答案

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

Access the subplot in question and change its settings like so.

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函数.

You can inspect how the scatter_matrix function goes about labeling at the link below. If you find yourself doing this over and over, consider copying the code into file and creating your own custom scatter_matrix function.

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

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

这样做的明显扩展(执行ax[0, 0].xaxis.set_visible(True)等)不起作用.由于某种原因,scatter_matrix似乎为轴[2,2]设置了刻度和标签,而没有使其可见,但是没有为其余的轴设置刻度和标签.如果您决定有必要在其他子图上显示刻度和标签,则必须更深入地研究上面链接的代码.

The obvious extensions of this, doing ax[0, 0].xaxis.set_visible(True) and so forth, do not work. For some reason, scatter_matrix seems to set up ticks and labels for axes[2, 2] without making them visible, but it does not set up ticks and labels for the rest. If you decide that it is necessary to display ticks and labels on other subplots, you'll have to dig deeper into the code linked above.

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

Specifically, change the conditions on the if statements to:

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

分别.我还没有测试过,但是我认为它可以解决问题.

respectively. I haven't tested that, but I think it will do the trick.

这篇关于 pandas 3x3散布矩阵缺失标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆