plt.imshow()
时间: 2023-10-29 14:39:52 浏览: 81
`plt.imshow()` is a function in the matplotlib library of Python that is used to display an image or matrix on a plot. It takes in a 2D array, which represents the image or matrix, and displays it on a plot with a color map that maps each value in the array to a specific color.
Syntax: `plt.imshow(arr, cmap=None, vmin=None, vmax=None, interpolation=None)`
Parameters:
- `arr`: 2D array that represents the image or matrix to be displayed.
- `cmap`: Colormap that maps values in the array to colors. Default is `None`, which uses the default colormap.
- `vmin`: Minimum value of the color map. Default is `None`, which uses the minimum value of the array.
- `vmax`: Maximum value of the color map. Default is `None`, which uses the maximum value of the array.
- `interpolation`: Interpolation method used for displaying the image. Default is `None`, which uses the default interpolation method.
Example:
```python
import matplotlib.pyplot as plt
import numpy as np
# create a 2D array
arr = np.random.rand(10, 10)
# display the image using plt.imshow()
plt.imshow(arr, cmap='gray')
# show the plot
plt.show()
```
Output:
![imshow output](https://i.imgur.com/8rGq3nl.png)
阅读全文