相关疑难解决方法(0)

将绘图保存到图像文件,而不是使用Matplotlib显示它

我正在编写一个快速而肮脏的脚本来动态生成绘图.我使用下面的代码(来自Matplotlib文档)作为起点:

from pylab import figure, axes, pie, title, show

# Make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]

explode = (0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor': '0.8', 'pad': 5})

show()  # Actually, don't show, just save to foo.png
Run Code Online (Sandbox Code Playgroud)

我不想在GUI上显示绘图,相反,我想将绘图保存到文件(例如foo.png),因此,例如,它可以在批处理脚本中使用.我怎么做?

python plot matplotlib

1060
推荐指数
20
解决办法
144万
查看次数

使用PIL使所有白色像素透明?

我正在尝试使用Python Image Library使所有白色像素透明.(我是一个C黑客试图学习python所以要温柔)我已经有转换工作(至少像素值看起来正确)但我无法弄清楚如何将列表转换为缓冲区来重新创建图片.这是代码

img = Image.open('img.png')
imga = img.convert("RGBA")
datas = imga.getdata()

newData = list()
for item in datas:
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
        newData.append([255, 255, 255, 0])
    else:
        newData.append(item)

imgb = Image.frombuffer("RGBA", imga.size, newData, "raw", "RGBA", 0, 1)
imgb.save("img2.png", "PNG")
Run Code Online (Sandbox Code Playgroud)

python image python-imaging-library

54
推荐指数
6
解决办法
7万
查看次数

Python PIL:如何在PNG中使区域透明?

我一直在使用PIL裁剪图像,现在我也想让某些矩形区域变得透明

from PIL import Image
im = Image.open("sample.png")
transparent_area = (50,80,100,200)
...
Run Code Online (Sandbox Code Playgroud)

我非常感谢一些代码,因为我无法找到它,非常感谢提前!

干杯,

霍夫

python png transparency image python-imaging-library

12
推荐指数
1
解决办法
2万
查看次数

Matplotlib:如何使背景透明?

我遇到了使情节本身透明的方法,但是如何使背景透明?有没有办法在没有 Qt 的情况下做到这一点?我希望绘图位于背景窗口上方,例如,假设我正在运行 Chrome,我希望绘图位于 chrome 窗口上方,并且其内容可见。

python matplotlib heatmap

3
推荐指数
1
解决办法
9818
查看次数