在Pandas中使散点图的标签垂直和水平 [英] Making the labels of the scatterplot vertical and horizontal in Pandas

查看:104
本文介绍了在Pandas中使散点图的标签垂直和水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pandas绘制散点图矩阵:from pandas.tools.plotting import scatter_matrix.问题是DataFrame中的列名太长,我需要它们在x轴上是垂直的,在y轴上是水平的,以便它们适合.我根本无法弄清楚如何在Pandas中做到这一点.我知道如何在matplotlib中做到这一点,但在Pandas中却不知道.

I'm using Pandas to draw a scatterplot matrix: from pandas.tools.plotting import scatter_matrix. The problem is that the names of the columns in the DataFrame are too long and I need them to be vertical in the x-axis and horizontal in the y-axis so they can fit. I'm not able to figure out at all how to do that in Pandas. I know how to do it in matplotlib but not in Pandas.

我的代码:

pylab.clf()
df = pd.DataFrame(X, columns=the_labels)
axs = scatter_matrix(df, alpha=0.2, diagonal='kde')

我需要使用pylab.clf(),因为我要绘制很多图形,因此每次调用pylab.figure()都会占用大量内存.

I need to use pylab.clf() because I'm plotting a lot of figures, so calling pylab.figure() each time is too memory consuming.

推荐答案

此答案的主要帮助: https://stackoverflow.com /a/18994338/2632856

a = [[1,2], [2,3], [3,4], [4, 5], [1, 6], [2,7], [1,8]]
df = pd.DataFrame(a,columns=['askdabndksbdkl','aooweoiowiaaiwi'])
axs = pd.scatter_matrix( df, alpha=0.2, diagonal='kde')
n = len(df.columns)
for x in range(n):
    for y in range(n):
        # to get the axis of subplots
        ax = axs[x, y]
        # to make x axis name vertical  
        ax.xaxis.label.set_rotation(90)
        # to make y axis name horizontal 
        ax.yaxis.label.set_rotation(0)
        # to make sure y axis names are outside the plot area
        ax.yaxis.labelpad = 50

这篇关于在Pandas中使散点图的标签垂直和水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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