python - 如何使用 MATPLOTLIB 设置标签?

标签 python matplotlib

我有我的形象 enter image description here

然后我试试这个

   #!/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

关于python - 如何使用 MATPLOTLIB 设置标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35605732/

相关文章:

python - 为什么我的网络服务器有时只传输部分响应?

python - 搁置(python)真的很奇怪

python - 考虑字段中的零值的字节字符串反序列化

python - 如何在动画的散点图中重新排序节点(更改深度)

python - Py2Exe,[Errno 2] 没有那个文件或目录 : 'numpy-atlas.dll'

python - Django South 迁移历史导致完整性错误

python - 创建每日滚动当前最高值系列

matplotlib - MNIST Matplotlib : showing color

python - Pyplot "cannot connect to X server localhost:10.0"尽管 ioff() 和 matplotlib.use ('Agg' )

python - 基于两个因素可视化错误