基于python的热力图heatmap函数使用

一、标出库引用

import seaborn as sns

二、函数具体使用

sns.heatmap(temp, annot=True, square=True, cmap="Blues)
plt.show()

其中,temp是n个变量构成的n*n的互相关系数矩阵,是DataFrame格式,其余参数是自己设定的参数。

三、参数说明

def heatmap(
    data, *,
    vmin=None, vmax=None, cmap=None, center=None, robust=False,
    annot=None, fmt=".2g", annot_kws=None,
    linewidths=0, linecolor="white",
    cbar=True, cbar_kws=None, cbar_ax=None,
    square=False, xticklabels="auto", yticklabels="auto",
    mask=None, ax=None,
    **kwargs
):

将矩形数据绘制为颜色编码矩阵。
参数分析:


 1. data : rectangular datase 2D dataset that can be coerced into an
    ndarray. If a Pandas DataFram is provided, the index/column
    information will be used to label the columns and rows.
 2. vmin, vmax : floats, optional Values to anchor the colormap,
    otherwise they are inferred from the data and other keyword
    arguments.
 3. cmap : matplotlib colormap name or object, or list of colors,
    optional. The mapping from data values to color space. If not
    provided, the default will depend on whether ``center`` is set.
 4. center : float, optional.                                           
    The value at which to center the colormap when plotting divergant
    data.Using this parameter will change the default ``cmap`` if none
    is specified.
 5. robust : bool, optional                                             
    If True and ``vmin`` or ``vmax`` are absent, the colormap range is
    computed with robust quantiles instead of the extreme values.
 
 6. annot : bool or rectangular dataset, optional.If True, write the data value in each cell. If an array-like with the same shape as ``data``, then use this to annotate the heatmap instead of the data. Note that DataFrames will match on position, not index.
 7. fmt : str, optional                                                 
  String formatting code to use when adding annotations.
 8. annot_kws : dict of key, value mappings, optional
Keyword arguments for :meth:`matplotlib.axes.Axes.text` when ``annot`` is True.
 
 9. linewidths : float, optional
                 Width of the lines that will divide each cell.
 10. linecolor : color, optional
             Color of the lines that will divide each cell.
 11. cbar : bool, optional
   Whether to draw a colorbar.
 12. cbar_kws : dict of key, value mappings, optional 
 Keyword arguments for :meth:`matplotlib.figure.Figure.colorbar`.
 13. cbar_ax : matplotlib Axes, optional
   Axes in which to draw the colorbar, otherwise take space from the main Axes.
 14. square : bool, optional
 If True, set the Axes aspect to "equal" so each cell will be square-shaped.
 15. xticklabels, yticklabels : "auto", bool, list-like, or int,
     optional
  If True, plot the column names of the dataframe. If False, don't plot  the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every  n label. If "auto", try to densely plot non-overlapping labels.
 16. mask : bool array or DataFrame, optional
 If passed, data will not be shown in cells where ``mask`` is True.
 Cells with missing values are automatically masked.
 17. ax : matplotlib Axes, optional  
Axes in which to draw the plot, otherwise use the currently-active  
 18. Axes.kwargs : other keyword arguments
   All other keyword arguments are passed to
   :meth:`matplotlib.axes.Axes.pcolormesh`.
 19. Returns
             -------
             ax : matplotlib Axes
                 Axes object with the heatmap.
     
     ```

你可能感兴趣的:(毕设,python)