img.set_data()
时间: 2023-09-15 18:20:03 浏览: 46
`img.set_data()` is a method used in Python's Matplotlib library to update the data of an existing image plot. It takes a 2D or 3D numpy array as input and updates the data in the plot. This method is commonly used for real-time data visualization.
Here's an example usage:
```python
import matplotlib.pyplot as plt
import numpy as np
# Create a 2D numpy array
data = np.random.rand(10, 10)
# Create an image plot of the array
img = plt.imshow(data)
# Update the data of the image plot
new_data = np.random.rand(10, 10)
img.set_data(new_data)
# Display the updated plot
plt.show()
```
This code generates a random 10x10 numpy array, creates an image plot of the array using `imshow()`, updates the data of the plot using `set_data()`, and displays the updated plot using `show()`.