Hello

I would like some help to understand a problem with matplotlib and wxpython.

I am developping a GUI where my plots are embedded on wxPanels on a wxNotebook (tabs). Under Windows, some themes don't use a single colour but a gradient as the tab background. Therefore, I'd like to make the background of my plots transparent.

Under Windows XP (whatever the theme), when I set the facecolor of the plot to 'none', the plot background becomes transparent, but the parts of the panel and of the notebook below as well, and I end up seeing other windows behind my GUI or the Windows desktop. I was expecting the transparency to "stop" at the layer below the plot and therefore see the.

I did a second experiment, where I overlayed two plots. The top one is larger than the one below. I make the top one partially transparent, to see the one below. The transparency is "stopped" in the area of the inferior plot, I see the desktop on the remaining parts, and where there is no plot the background of my panel.

I'm attaching the code for the second experiment.

I'm running XP 32bits with the Classic theme, python 2.7.3, matplotlib 1.2.0 and wxpython 2.9.4-msw.

Thanks for your help
--
Sylvain
import wx
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.patches import Rectangle
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
import wxversion
import sys

class MyFrame ( wx.Frame ):
    
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = 
wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 300,650 ), style = 
wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        
        
        bSizer4 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, 
wx.DefaultSize, wx.TAB_TRAVERSAL )
        self.m_panel2.SetBackgroundColour( wx.SystemSettings.GetColour( 
wx.SYS_COLOUR_ACTIVECAPTION ) )
        
        bSizer4.Add( self.m_panel2, 1, wx.EXPAND |wx.ALL, 5 )
        
        self.m_panel2.Layout()
        
        self.SetSizer( bSizer4 )
        self.Layout()
        
        self.Centre( wx.BOTH )
    
    def __del__( self ):
        pass
    

class MyPlot:
    def __init__(self, panel):
        self.panel = panel
        
        # This figure is behind
        self.panel.figure = Figure(figsize=(2,2), dpi=None)
        self.panel.canvas = FigureCanvasWxAgg(self.panel, -1, self.panel.figure)
        self.panel.axes = self.panel.figure.add_axes([0.3,0.3,0.5,0.5])
        patch = Rectangle((0,0), 0.3, 0.2, facecolor='red')
        self.panel.axes.add_patch(patch)
        
        # This figure is on top
        self.panel.figure2 = Figure(figsize=(3,3), dpi=None)
        self.panel.canvas2 = FigureCanvasWxAgg(self.panel, -1, 
self.panel.figure2)
        self.panel.axes2 = self.panel.figure2.add_axes([0.3,0.3,0.5,0.5])
        patch2 = Rectangle((0.5,0.5), 0.4, 0.1, facecolor='blue')
        self.panel.axes2.add_patch(patch2)

        # Make the top figure transparent
        # self.panel.figure2.set_facecolor('None') # equivalent to 
self.panel.figure2.patch.set_alpha(0)
        
        # self.panel.figure.patch.set_alpha(0.5)
        self.panel.figure2.patch.set_alpha(0.5)

        # Draw everything
        self.panel.Refresh()
        self.panel.canvas.draw()

        
print "python " + str(sys.version_info)
print "wx " + str(wxversion.getInstalled())
print "matplotlib " + matplotlib.__version__ 

app = wx.App(0)
window = MyFrame(None)
plot = MyPlot(window.m_panel2)
window.Show()
app.MainLoop()
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to