除了这种方法,我还有什么办法来读取并显示matlab保存的fig格式的图片吗?
时间: 2024-02-18 19:06:30 浏览: 262
除了将fig图片导出为其他格式,然后用Python的matplotlib库读取并显示外,还有一种方法可以读取并显示matlab保存的fig格式的图片,那就是使用Matplotlib的mplot3d库中的`mplot3d.Axes3D`类。这个类可以直接读取matlab保存的fig文件,并将其显示出来。
具体步骤如下:
1. 在Python中导入`mplot3d`库:
```python
from mpl_toolkits import mplot3d
```
2. 创建`mplot3d.Axes3D`对象,从而读取matlab保存的fig文件:
```python
fig = plt.figure()
ax = mplot3d.Axes3D(fig)
ax.view_init(elev=48, azim=134)
ax.dist = 8
ax.azim = 134
ax.elev = 48
ax.set_axis_off()
ax.mouse_init()
ax.plot()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].remove()
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_edgecolor('none')
ax.get_children()[0].set_linewidth(0.0)
ax.get_children()[0].set_facecolor('none')
ax.get_children()[0].set_alpha(0.0)
ax.get_children()[0].set_linewidth(0.0)
ax.set_xlim3d(left=-1, right=1)
ax.set_ylim3d(bottom=-1, top=1)
ax.set_zlim3d(bottom=-1, top=1)
ax.invert_zaxis()
ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1, 1, 0.5, 1]))
fig.canvas.draw()
# 显示图片
plt.show()
```
这个方法可能比较复杂,但是可以读取matlab保存的fig文件,并将其以3D的形式显示出来。
阅读全文
相关推荐

















