如何自定义散点图以查看所有标题? [英] How to customize a scatter matrix to see all titles?

查看:162
本文介绍了如何自定义散点图以查看所有标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行此代码来构建分散矩阵.问题在于该图看起来像一团糟,因为无法看到变量的名称(请参见下图).有什么方法可以改变标题的方向并关闭带有数字的对勾?

I'm running this code to build a scatter matrix. The problem is that the plot looks like a mess, because it's impossible to see the names of variables (see image below). Is there any way to change the orientation of titles and switch off the ticks with numbers?

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()

推荐答案

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

As a minimal scatter_matrix example to switch off axis ticks and rotate the labels,

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()

并且类似地,您可以使用scatter_matrix返回的句柄中包含的任何轴对象来调整标签,调整大小等.结果是,

and similarly, you can adjust labels, resize, etc with any of the axis objects contained in the returned handle from scatter_matrix. This results in,

这篇关于如何自定义散点图以查看所有标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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