Skip to main content
 首页 » 编程设计

python之如何使用 MATPLOTLIB 设置标签

2024年10月24日10EasonJim

我有我的头像

那我试试这个

   #!/usr/bin/python 
import os,sys 
import Image 
import matplotlib.pyplot as plt 
 
jpgfile = Image.open("t002.jpg") 
fig = plt.imshow(jpgfile) 
ax = fig.add_subplot(111) 
ax.set_xlabel('normlized resistivities') 
ay.set_ylabel('normlized velocities') 
fig.savefig("fig.jpg") 

但是我有

AttributeError: 'AxesImage' object has no attribute 'add_subplot' 

如何设置 xlabel 和 ylabel,然后将新图像保存为文件?

请您参考如下方法:

简单的做就够了

plt.figure() 
plt.imshow(jpgfile) 
plt.xlabel('normlized resistivities') 
plt.ylabel('normlized velocities') 
plt.savefig('out.jpg') 

您当前的错误是因为 imshow 没有返回 Figure。