How to implement visual heat map in python
This article mainly introduces how to implement visual heat map in python. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look
Heat map
1. Use heat map to see the similarity of multiple features in the data table. Refer to the official API parameters and address:
seaborn.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) Heat map input data parameters:
data: Matrix data set, yes It is an array of numpy, or it can be a DataFrame of pandas. If it is a DataFrame, the index/column information of df will correspond to the columns and rows of the heatmap respectively, that is, pt.index is the row label of the heat map, and pt.columns is the column label of the heat map
(2) Heat map matrix block color parameters:
vmax, vmin: are the maximum and minimum color value ranges of the heat map respectively. The default is determined based on the values in the data table
cmap: Mapping from numbers to color space, the value is the colormap name or color object in the matplotlib package, or a list representing colors; change the parameter default value: set according to the center parameter
center: When the data table values are different, set the color center alignment value of the heat map; by setting the center value, you can adjust the overall depth of the generated image color; when setting the center data, if there is data overflow, manually The set vmax and vmin will automatically change
robust: The default value is False; if it is False and the values of vmin and vmax are not set, the color mapping range of the heat map is based on the robustness Quantile setting, instead of extreme value setting
(3) Heat map matrix block annotation parameters:
annot (abbreviation of annotate): default Value False; if it is True, data is written in each square of the heat map; if it is a matrix, data corresponding to the matrix is written in each square of the heat map
fmt: String format Code, data format for identifying numbers on the matrix, such as retaining several digits after the decimal point
annot_kws: Default value is False; if it is True, set the size, color, and font of the numbers on the heat map matrix, matplotlib package Font settings under the text class; official document:
(4) Spacing and spacing line parameters between heat map matrix blocks:
linewidths: Define the " The gap size between "matrix patches" that represent pairwise feature relationships
linecolor: The color of the line that divides each matrix patch on the heat map. The default value is 'white'
(5) Heat map color scale bar parameters:
cbar: Whether to draw a color scale bar on the side of the heat map. The default value is True
cbar_kws: When drawing color scale bars on the side of the heat map, the relevant font settings, the default value is None
cbar_ax: When drawing the color scale bars on the side of the heat map, the scale bar position settings, the default value is None
(6) square: Set the shape of the heat map matrix, the default value is False
xticklabels, yticklabels:xticklabels controls each column Output of label names; yticklabels controls the output of label names for each line. The default value is auto. If True, the column name of the DataFrame is used as the label name. If False, no row label names are added. If it is a list, the label name is changed to the content given in the list. If it is an integer K, label every K labels on the graph. If it is auto, the label spacing of the labels will be automatically selected, and the non-overlapping part (or all) of the label names will be output.
mask: Controls whether a certain matrix block is displayed. The default value is None. If it is a Boolean DataFrame, cover the True position in the DataFrame with white
ax: Set the coordinate axis of the drawing. Generally, when drawing multiple subgraphs, you need to modify the coordinates of different subgraphs. Value
**kwargs:All other keyword arguments are passed to ax.pcolormesh
Heat map matrix block color parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Heat map matrix block annotation parameters
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 8 9 |
|
热力图矩阵块之间间隔及间隔线参数
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
用mask实现:突出显示某些数据
1 2 3 4 |
|
The above is the detailed content of How to implement visual heat map in python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

The key to running Jupyter Notebook in VS Code is to ensure that the Python environment is properly configured, understand that the code execution order is consistent with the cell order, and be aware of large files or external libraries that may affect performance. The code completion and debugging functions provided by VS Code can greatly improve coding efficiency and reduce errors.
