How can I create a color bar in matplotlib?
How can I create a color bar in matplotlib?
How can I create a color bar in matplotlib?
solveurit24@gmail.com Changed status to publish February 13, 2025
Use plt.colorbar() to add a color bar to a plot.
import matplotlib.pyplot as plt
import numpy as np
# Create sample data
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) + np.cos(Y)
# Create a pcolor plot
plt.pcolor(X, Y, Z)
# Add color bar
plt.colorbar(label='Z')
# Show the plot
plt.show()
solveurit24@gmail.com Changed status to publish February 13, 2025