在Python中,使用Matplotlib库可以创建画布并显示图形。以下是创建和显示画布的基本步骤:
1. 导入`matplotlib.pyplot`模块:
```python
import matplotlib.pyplot as plt
2. 创建一个画布实例:
```python
plt.figure()
3. (可选)设置画布的属性,如大小和分辨率:
```python
plt.figure(figsize=(8, 6), dpi=100)
4. 显示画布:
```python
plt.show()
以上代码将创建一个8x6英寸的画布,并在新窗口中显示它。如果你想保存画布为图像文件,可以使用`savefig`方法:
```python
plt.savefig('filename.png')
请确保在运行代码前已经安装了Matplotlib库,如果没有安装,可以使用`pip install matplotlib`命令进行安装