Skip to content

Commit b8f86af

Browse files
committed
test(live): add live_test_plotgen for interactive plotgen usage and custom plot generation examples
1 parent 3ee4b5f commit b8f86af

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

test/live/live_test_plotgen.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
4+
from plotsense.plot_generator.generator import plotgen
5+
6+
df = pd.DataFrame({
7+
"a": range(10),
8+
"b": range(10, 20)
9+
})
10+
11+
suggestions_df = pd.DataFrame([
12+
{"plot_type": "scatter", "variables": "a,b"}
13+
])
14+
15+
# Standard plot
16+
fig1 = plotgen(df, 0, suggestions_df, generator="smart")
17+
18+
# ---------
19+
20+
# Custom plot
21+
def my_custom_plot(df, vars, **kwargs):
22+
fig, ax = plt.subplots()
23+
ax.plot(df[vars[0]], df[vars[1]], color="red")
24+
return fig
25+
26+
fig2 = plotgen(
27+
df, 0, suggestions_df,
28+
generator="smart",
29+
plot_function=my_custom_plot,
30+
plot_type="my_line"
31+
)
32+
33+
# ---------
34+
35+
# Create sample DataFrame
36+
df = pd.DataFrame({
37+
"height": [165, 170, 175, 160, 172, 168, 180, 177, 169, 174]
38+
})
39+
40+
# Simulate a recommendation DataFrame (just like your usual `suggestions_df`)
41+
suggestions_df = pd.DataFrame([
42+
{"plot_type": "kde", "variables": "height"}
43+
])
44+
45+
# Generate KDE Plot
46+
fig_kde = plotgen(df, 0, suggestions_df, generator="smart")
47+
48+
# ---------
49+
50+
# Create sample DataFrame
51+
df = pd.DataFrame({
52+
"scores": [60, 72, 85, 90, 66, 75, 88, 93, 70, 80]
53+
})
54+
55+
# Simulate recommendation DataFrame
56+
suggestions_df = pd.DataFrame([
57+
{"plot_type": "ecdf", "variables": "scores"}
58+
])
59+
60+
# Generate ECDF Plot
61+
fig_ecdf = plotgen(df, 0, suggestions_df, generator="smart")
62+
63+
plt.show()
64+

0 commit comments

Comments
 (0)