Python 了解 Pandas 散点矩阵图中的对角线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26360759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:24:08  来源:igfitidea点击:

Understanding the diagonal in Pandas' scatter matrix plot

pythonpandas

提问by Hyman Twain

I'm plotting a scatter plot with Pandas. I can understand the plot, except the curves in diagonal plots. Can someone explain to me what they mean?

我正在绘制散点图Pandas。除了对角线图中的曲线,我能理解这个图。有人可以向我解释他们的意思吗?

Image:

图片:

enter image description here

在此处输入图片说明

Code:

代码:

import pylab
import numpy as np
from pandas.tools.plotting import scatter_matrix
import pandas as pd

def make_scatter_plot(X, name):    
    """
    Make scatterplot.

    Parameters:
    -----------
    X:a design matrix where each column is a feature and each row is an observation.
    name: the name of the plot.
    """
    pylab.clf()
    df = pd.DataFrame(X)
    axs = scatter_matrix(df, alpha=0.2, diagonal='kde')

    for ax in axs[:,0]: # the left boundary
        ax.grid('off', axis='both')
        ax.set_yticks([0, .5])

    for ax in axs[-1,:]: # the lower boundary
        ax.grid('off', axis='both')
        ax.set_xticks([0, .5])

    pylab.savefig(name + ".png")

回答by Wilduck

As you can tell, the scatter matrix is plotting each of the columns specified against each other column.

如您所知,散点矩阵将指定的每一列相对于其他列进行绘制。

However, in this format, when you got to a diagonal, you would see a plot of a column against itself. Since this would always be a straight line, Pandas decides it can give you more useful information, and plots the density plot of just that column of data.

但是,在这种格式中,当您到达对角线时,您会看到一个柱状图。由于这始终是一条直线,Pandas 认为它​​可以为您提供更多有用的信息,并绘制仅该列数据的密度图。

See http://pandas.pydata.org/pandas-docs/stable/visualization.html#density-plot.

请参阅http://pandas.pydata.org/pandas-docs/stable/visualization.html#density-plot

If you would rather have a histogram, you could change your plotting code to:

如果您更喜欢直方图,您可以将绘图代码更改为:

axs = scatter_matrix(df, alpha=0.2, diagonal='hist')

回答by scarybuh

Plotting methods allow for a handful of plot styles other than the default Line plot. These methods can be provided as the kind keyword argument to plot(). These include:

绘图方法允许使用除默认线图之外的少数绘图样式。这些方法可以作为 plot() 的 kind 关键字参数提供。这些包括:

  • ‘bar' or ‘barh' for bar plots
  • ‘hist' for histogram
  • ‘box' for boxplot
  • ‘kde' or 'density' for density plots
  • ‘area' for area plots
  • ‘scatter' for scatter plots
  • ‘hexbin' for hexagonal bin plots
  • ‘pie' for pie plots
  • 'bar' 或 'barh' 用于条形图
  • 'hist' 用于直方图
  • 箱线图的“箱”
  • 密度图的“kde”或“密度”
  • 'area' 用于面积图
  • 散点图的 'scatter'
  • 'hexbin' 用于六边形 bin 图
  • 'pie' 表示饼图

https://pandas.pydata.org/pandas-docs/stable/visualization.html

https://pandas.pydata.org/pandas-docs/stable/visualization.html