Search code examples
pythonmatplotlibwxpythonseabornkernel-density

Embedding Seaborn plot in WxPython panel


I would like to ask how I could embed a seaborn figure in wxPython panel.

Similarly to this post, I want to embed an external figure in a wxPython panel. I would like a specific panel of my wxPython GUI to plot the density contours of my data based on bandwidth values of a Gaussian kernel, according to Seaborn's kdeplot function, along with a scatter plot of the data points. Here is an example of what I would like to be plotted in the panel: example

Until now, I have managed to get what I want in a separate figure out of the wxPython panel.Is it possible to embed a seaborn plot in a wxPython panel or should find an alternative way to implement what I want?

Below is the specific part of my code that generates the plot in case it is needed:

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 part of the code plots in the wxPython panel the scattered data points and creates an external figure for the density contours. But, if I try ax.sns.kdeplot(...) I get the error

Attribute Error: AxesSubplot object has not attribute .sns

I don't know if I can embed a Seaborn figure in wxPython panel or I should try implement it in another way. Any suggestions?

Thanks in advance.


Solution

  • I don't know anything about wxPython but if you want to plot onto a specific axes use the ax keyword argument.