Skip to content

Commit aaf8924

Browse files
committed
feat:Added selectable color palettes.
1 parent adcc4d4 commit aaf8924

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Presentations/DSSG-SouthFL-2025/qr-app.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454
def sns_plot(obj,
5555
title="", width=800, height=600,
5656
data_color: (str | None) = "grey",
57-
date_plot: bool = False, epoch_start="1900-01-01",
57+
date_plot: bool = False,
58+
epoch_start="1900-01-01",
5859
background_color="#1f1f1f",
60+
palette="Set1",
5961
point_size=2,
6062
**kwargs):
6163
"""
@@ -82,17 +84,20 @@ def sns_plot(obj,
8284
# Set background color
8385
ax.set_facecolor(background_color)
8486

85-
8687
# Plot data points
8788
sns.scatterplot(
8889
x=xs,
8990
y=obj.take_data()[:, 1],
90-
color=data_color, ax=ax, size=point_size, linewidth=0, alpha = 1, legend=False)
91+
color=data_color,
92+
ax=ax, size=point_size, linewidth=0, alpha = 1, legend=False)
93+
94+
# Create a color palette
95+
paletteArray = sns.color_palette(palette, n_colors=len(obj.take_regression_quantiles()))
9196

9297
# Plot each regression quantile
9398
for i, p in enumerate(obj.take_regression_quantiles().keys()):
9499
y_fit = [obj.take_regression_quantiles()[p](xi) for xi in obj.take_data()[:, 0]]
95-
sns.lineplot(x=xs, y=y_fit, ax=ax, label=f'{p}', linewidth=3)
100+
sns.lineplot(x=xs, y=y_fit, ax=ax, label=f'{p}', linewidth=3, color=paletteArray[i])
96101

97102
# Set title
98103
ax.set_title(title)
@@ -132,7 +137,11 @@ def is_float(string):
132137
ui.input_checkbox("datePlotQ", "Date axis", value=True),
133138
ui.card(
134139
ui.output_plot("distPlot"),
135-
)
140+
),
141+
ui.input_select(id = "palette", label = "Color palette:",
142+
choices=["Set1", "Set2", "Dark2", "Accent", "Paired", "Pastel1", "Pastel2"],
143+
selected="Set1"
144+
),
136145
)
137146

138147
def server(input: Inputs, output: Outputs, session: Session):
@@ -155,6 +164,7 @@ def distPlot():
155164
date_plot=input.datePlotQ(),
156165
template=template,
157166
data_color=data_color,
167+
palette=input.palette(),
158168
background_color = '#1F1F1F',
159169
point_size = 2,
160170
width = 800, height = 300)

0 commit comments

Comments
 (0)