Write a python function that takes a 2d np array and plots a depth color map of it with…
- User
Write a python function that takes a 2d np array and plots a depth color map of it with colorbar next to the plot. Think step by step.
Assistant
Here is a Python function to plot a depth color map of a 2D NumPy array with a colorbar:
import matplotlib.pyplot as plt import numpy as np def plot_depth_colormap(data): # Create figure and axes fig, ax = plt.subplots() # Generate the depth color map cmap = plt.cm.jet # Plot the depth map im = ax.imshow(data, cmap=cmap) # Add a colorbar cbar = fig.colorbar(im, ax=ax) # Set the colorbar label cbar.set_label('Depth') # Show the plot plt.show()To use this:
- Pass in a 2D NumPy array (data)
- It will create a figure and axes
- Generate a "jet" colormap from matplotlib
- Plot the data as an image with the colormap
- Add a colorbar linked to the image
- Set the colorbar label
- Show the plot
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.