如何自定义散布矩阵以查看所有标题?

Kla*_*sos 6 python matplotlib pandas

我正在运行此代码来构建分散矩阵.问题是情节看起来很乱,因为不可能看到变量的名称(见下图).有没有办法改变标题的方向,并用数字关闭刻度线?

import pandas as pd
import matplotlib.pyplot as plt

train = pd.read_csv('data/train.csv', parse_dates=[0])

plt.figure()
a = pd.scatter_matrix(train, alpha=0.05, figsize=(10,10), diagonal='hist')
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Ed *_*ith 7

作为scatter_matrix关闭轴刻度和旋转标签的最小示例,

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pandas.tools.plotting import scatter_matrix

df = pd.DataFrame(np.random.randn(1000, 4), columns=['long label', 'testing', 'another label', 'something else'])

sm = scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')

#Change label rotation
[s.xaxis.label.set_rotation(45) for s in sm.reshape(-1)]
[s.yaxis.label.set_rotation(0) for s in sm.reshape(-1)]

#May need to offset label when rotating to prevent overlap of figure
[s.get_yaxis().set_label_coords(-0.3,0.5) for s in sm.reshape(-1)]

#Hide all ticks
[s.set_xticks(()) for s in sm.reshape(-1)]
[s.set_yticks(()) for s in sm.reshape(-1)]

plt.show()
Run Code Online (Sandbox Code Playgroud)

同样,您可以使用返回的句柄中包含的任何轴对象调整标签,调整大小等scatter_matrix.结果是,

在此输入图像描述