Matplotlib.pyplot.hot() in Python


matplotlib.pyplot.hot() is a function in the Matplotlib library of Python programming language. It is used to create a colormap that ranges from black to red to yellow to white. It is commonly used to represent heatmaps, where the darker colors represent lower values and the brighter colors represent higher values.

Syntax:

matplotlib.pyplot.hot(N=256, gamma=1.0)

Parameters: - N: The number of color levels in the colormap. Default is 256. - gamma: The gamma correction factor. Default is 1.0.

Returns: - A colormap object.

Example:

import matplotlib.pyplot as plt
import numpy as np

# Create a 2D array of random values
data = np.random.rand(10, 10)

# Create a heatmap using the 'hot' colormap
plt.imshow(data, cmap='hot')

# Add a colorbar to the plot
plt.colorbar()

# Show the plot
plt.show()

Output:

Another example with custom number of color levels:

import matplotlib.pyplot as plt
import numpy as np

# Create a 2D array of random values
data = np.random.rand(10, 10)

# Create a heatmap using the 'hot' colormap with 10 color levels
plt.imshow(data, cmap='hot', vmin=0, vmax=1, interpolation='nearest', aspect='auto')

# Add a colorbar to the plot
plt.colorbar()

# Show the plot
plt.show()

Output:



About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.