如何修改pandas plotting integration?

maz*_*res 4 python matplotlib pandas

我正在尝试修改Pandas上可用的scatter_matrix图.

简单的用法是IRIS散射矩阵即

获得了:

iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
pd.tools.plotting.scatter_matrix(df, diagonal='kde', grid=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我想做几处修改,其中包括:

  • 设法关闭所有地块的网格
  • 旋转x任意y标签90度
  • 打开嘀嗒声

有没有办法让我修改pandas的输出而不必重写我自己的散点图函数?从哪里开始添加不存在的选项,微调等?

谢谢 !

beh*_*uri 7

pd.tools.plotting.scatter_matrix返回它绘制的轴数组; 左下边界轴对应于指数[:,0][-1,:].可以循环遍历这些元素并应用任何类型的修改.例如:

axs = pd.tools.plotting.scatter_matrix(df, diagonal='kde')

def wrap(txt, width=8):
    '''helper function to wrap text for long labels'''
    import textwrap
    return '\n'.join(textwrap.wrap(txt, width))

for ax in axs[:,0]: # the left boundary
    ax.grid('off', axis='both')
    ax.set_ylabel(wrap(ax.get_ylabel()), rotation=0, va='center', labelpad=20)
    ax.set_yticks([])

for ax in axs[-1,:]: # the lower boundary
    ax.grid('off', axis='both')
    ax.set_xlabel(wrap(ax.get_xlabel()), rotation=90)
    ax.set_xticks([])
Run Code Online (Sandbox Code Playgroud)

分散