Complete the code to create a heatmap using plt.pcolormesh.
import matplotlib.pyplot as plt import numpy as np data = np.array([[1, 2], [3, 4]]) plt.[1](data) plt.show()
The plt.pcolormesh function creates a heatmap from a 2D array.
Complete the code to add a colorbar to the heatmap.
import matplotlib.pyplot as plt import numpy as np data = np.array([[5, 10], [15, 20]]) mesh = plt.pcolormesh(data) plt.[1]() plt.show()
The plt.colorbar() function adds a color scale bar to the heatmap.
Fix the error in the code to correctly display the heatmap with a custom colormap.
import matplotlib.pyplot as plt import numpy as np data = np.array([[1, 4], [9, 16]]) plt.pcolormesh(data, cmap=[1]) plt.colorbar() plt.show()
The cmap parameter expects a string name of the colormap in quotes.
Fill both blanks to create a heatmap with labeled axes and a title.
import matplotlib.pyplot as plt import numpy as np data = np.array([[2, 3], [4, 5]]) plt.pcolormesh(data) plt.xlabel([1]) plt.title([2]) plt.colorbar() plt.show()
Use plt.xlabel to label the x-axis and plt.title to add a title to the plot.
Fill all three blanks to create a heatmap with custom x and y ticks and a colorbar label.
import matplotlib.pyplot as plt import numpy as np data = np.array([[7, 8], [9, 10]]) mesh = plt.pcolormesh(data) plt.xticks([1]) plt.yticks([2]) plt.colorbar(mesh, label=[3]) plt.show()
Use plt.xticks and plt.yticks to set tick positions. The colorbar label is a string describing the data.
