Making the labels of the scatterplot vertical and horizontal in Pandas

前端 未结 2 2313
-上瘾入骨i
-上瘾入骨i 2021-02-20 14:36

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 <

2条回答
  •  面向向阳花
    2021-02-20 15:29

    Major help from this answer: 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
    

    enter image description here

提交回复
热议问题