根据matplotlib文档,我试图使用patch.set_facecolor(' none')
设置透明背景图和子图。它适用于子图,但不适用于图。
def create_plot_win(self,label_list,set_prop=1,box=None):
ax_list=[]
fig1 = Figure(tight_layout=True)
fig1.patch.set_facecolor('none')
l=len(label_list)
for i in range(len(label_list)):
ax_list.append(fig1.add_subplot(l,1,i+1))
ax_list[-1].patch.set_facecolor('none')
canvas = FigureCanvas(fig1)
toolbar=NavigationToolbar(canvas,box)
box.pack_start(toolbar,False,False,0)
if l ==1:return canvas,fig1,toolbar,ax_list[0]
如何将图形背景设置为透明?
我正在使用python-2.7处理windows-8.1。
如果我将face face设置为' none',我会得到带黑色背景的图形,而我的应用程序背景是图像。
有关截屏,请点击此处screen shot
import pygtk
pygtk.require('2.0')
import gtk
import matplotlib
matplotlib.use('GtkAgg')
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as Canvas
import pylab
import cairo
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_position(gtk.WIN_POS_CENTER)
self.fig = matplotlib.pyplot.figure()
self.ax = self.fig.add_subplot(1,1,1)
self.canvas = Canvas(self.fig)
self.ax.plot([0,1,2,3,4],[0,1,4,9,16])
self.ax.patch.set_facecolor('none')
self.fig.patch.set_facecolor('none')
self.pltbox = gtk.VBox(False, 0)
self.pltbox.pack_start(self.canvas)
self.add(self.pltbox)
self.connect("destroy",gtk.main_quit)
self.show_all()
PyApp()
gtk.main()