本文介绍了如何修改 pandas 图的整合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 scatter_matrix 在熊猫上可用的情节.

I'm trying to modify the scatter_matrix plot available on Pandas.

简单的用法是

获得成就:

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

我想做几处修改,其中:

I want to do several modification, among which:

  • 管理在所有地块上关闭网格
  • 将x个y标签旋转90度
  • 关闭刻度线

我是否可以在不重写自己的散点图函数的情况下修改熊猫的输出?从哪里开始添加不存在的选项,进行微调等?

谢谢!

推荐答案

pd.tools.plotting.scatter_matrix返回绘制轴的数组;左下边界轴对应于索引[:,0][-1,:].可以遍历这些元素并进行各种修改.例如:

pd.tools.plotting.scatter_matrix returns an array of the axes it draws; The lower left boundary axes corresponds to indices [:,0] and [-1,:]. One can loop over these elements and apply any sort of modifications. For example:

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

这篇关于如何修改 pandas 图的整合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:35