SoFunction
Updated on 2024-11-16

Python pytorch implementation for plotting one-dimensional heat maps

heat map

A Heat Map is a map that identifies the location of numerical points using two categorized fields represented by the X- and Y-axes.The size of the value is represented by the color of the rectangle at the corresponding position., darker colors represent larger values.

A heat map is a very specific type of map that shows what is happening in non-clickable areas.Heat maps are very concerned about distributionIt can be used without axes, and its background is usually a picture or a map, usually using a rainbow color scheme for the display.

Heat maps are generally predominantly two-dimensional and are mostly used in image processing.

Heat maps are mainly used to show the distribution of continuous type data. For example, using color to show the difference in the amount of data from different regions within a certain range, website analytics, etc.

dominance: Good looking, easy to understand, more intuitive and effective data information, can clearly present the distribution, frequency or density of data in geospatial situation.

drawbacks: The effect is too soft to be used as a precise representation of data and is not suitable for comparing the size of a single variable.

One-dimensional heat map ----- overall distribution

Create a one-dimensional heat map from the data in the line graph, similar to a histogram, plotting different colors based on the frequency of occurrence of each bins

coding

The imshow keyword parameter can be used to set imshow to set the data range of the image. This sets the range using the tuple (left, right, bottom, top).

Using the minimum and maximum bin edges of the histogram in the range moves the data to its original value.

import  as plt
import numpy as np; (1)
# Canvas size
[""] = 5,2
# Sequentially generate 96 numbers between -56 and 40
pos = (-56,40) #there are 96 numbers from -56 to 39
print len(pos), (), ()
# Generate 96 random numbers
p = (len(pos))
# Random numbers into probabilities
p= p/(p)
# Pick 4000 numbers in pos based on probability of occurrence of each number
a= (pos, size=4000, p=p)
# Divide the range of values of a into 96 bins
bins=(-56,41) 
# Get the histogram distribution, hist denotes the number of numbers in each bin, edges denote the boundaries of the bin
hist, edges = (a, bins)
hist=hist[,:]
# Heat map x-axis and y-axis ranges
extent=[(), (),0,1]
#Drawing
(hist, aspect ="auto", cmap="viridis", extent=extent)
().set_yticks([])
()

One-dimensional heat maps ---- data changes

Change the color according to the fluctuation of the data itself, depending on the size of the value itself.

Example graph, you can see that the heat map is redder when the value is large and bluer when the value is small

coding

import  as plt
import numpy as np; (1)
# Canvas size
[""] = 5,4
# Generate 40 values for the sin function
x = (range(40))
# Calculate the mean, i.e., the distribution within a segment, for every x numbers (taken here as 1, i.e., plotting the distribution for each number)
a = (1,-1)
a = (a, axis=0)
a=a[,:]
# Heat mapping
figure = ()
axes = figure.add_subplot(211)
(a,aspect ="auto",cmap="Spectral_r", interpolation='bilinear')
# Do not show horizontal and vertical coordinates
([])
([])
# Plotting raw data
(212)
(range(len(x)),x)
# x-axis display ranges from the first number to the last
((0,len(x)-1))
()

attention heat mapping principle

The difficulty lies in data acquisition, obtain the last layer of gradient data, you can know the focus of attention, according to the gradient data resize to the original data, and then draw theHeat maps (based on data changes), after which it corresponds to the original data to obtain the network'sHigh Response Thermogram

To this article on Python pytorch implementation of drawing a one-dimensional heat map is introduced to this article, more related Python drawing a one-dimensional heat map content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future!