Nesting a Seaborn Plot in a WxPython Panel

I would like to ask how I could embed a sea tree figure in the wxPython panel.

Like this post, I want to embed an external shape in the wxPython panel. I need a specific panel of my wxPython GUI to plot the density profiles of my data based on the width of the Gaussian kernel, according to Seaborn kdeplot , as well as a scatter plot of the data points. Here is an example of what I would like to build in the panel: example

So far I have managed to get what I want in a separate figure from the wxPython panel. Can I embed a seashore plot in the wxPython panel, or find an alternative way to implement what I want?

Below is a specific part of my code that generates a chart if necessary:

 import seaborn as sns import numpy as np fig = self._view_frame.figure data = np.loadtxt(r'data.csv',delimiter=',') ax = fig.add_subplot(111) ax.cla() sns.kdeplot(data, bw=10, kernel='gau', cmap="Reds") ax.scatter(data[:,0],data[:,1], color='r') fig.canvas.draw() 

This piece of code displays the scattered data points in the wxPython panel and creates an external shape for the density loops. But, if I try ax.sns.kdeplot(...) , I get an error

Attribute Error: AxesSubplot object does not have .sns attribute

I do not know if I can insert a Seaborn shape into the wxPython panel, or should I try to implement it differently. Any suggestions?

Thanks in advance.

+5
source share
2 answers

I don't know anything about wxPython, but if you want to draw on specific axes, use the ax keyword argument.

+2
source

I have never used Seaborn, but I think because the document says: "Seaborn is a matplotlib-based Python visualization library", you can probably use an MPL class called FigureCanvasWxAgg.

Here is sample code for embedding an MPL figure in wxPython.

 import numpy as np import wx import matplotlib matplotlib.use('WXAgg') from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg import seaborn class test(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title='Main frame') # just a normal MPL "Figure" object figure = Figure(None) # Place a widget to hold MPL figure. no sizer because this is the only widget fc = FigureCanvasWxAgg(self, -1, figure) # your plotting code here, this can be sns calls i think subplot = figure.add_subplot(111) subplot.plot(np.arange(10)) # Lastly show them self.Show() if __name__ == '__main__': app = wx.App(0) testframe = test() app.MainLoop() 

Perhaps you, perhaps, just replace the build code with sns material and just make sure that it displays the "Picture" object from MPL.

PS. Out of interest, I installed it pip, and only the import of the seabed has already changed the MPL style. So it seems to work. Due to calling matplotlib.use, you will want to import the ship after importing the MPL.

enter image description here

+2
source

All Articles