Streamlit + Seaborn JointPlot Problem

This Code produces a white square instead of the figure. Does anyone know why this is happening?

Python 3.11.0
Streamlit, version 1.28.2

import streamlit as st
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

Set a seed for reproducibility

np.random.seed(42)

Generate random data

data = {
“Isc”: np.random.uniform(1, 20, 10), # Random values between 1 and 20
“PCE”: np.random.uniform(1, 20, 10), # Random values between 1 and 20
“pixel type”: np.random.choice([“large”, “small”], 10) # Random choice between “large” and “small”
}

Create a DataFrame

df = pd.DataFrame(data)

fig2 = plt.figure(figsize=(6,3))

g = sns.jointplot(data=df, x=“Isc”, y=“PCE”, hue=“pixel type”, ratio=5, dropna=True, marginal_ticks=True)
g.plot_joint(sns.kdeplot, color=“r”, zorder=0, levels=1)

st.pyplot(fig2)

Because sns.jointplot ignores the current figure and creates a new one.

1 Like

Thanks!!! i did not know that

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.