54
54
def sns_plot (obj ,
55
55
title = "" , width = 800 , height = 600 ,
56
56
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" ,
58
59
background_color = "#1f1f1f" ,
60
+ palette = "Set1" ,
59
61
point_size = 2 ,
60
62
** kwargs ):
61
63
"""
@@ -82,17 +84,20 @@ def sns_plot(obj,
82
84
# Set background color
83
85
ax .set_facecolor (background_color )
84
86
85
-
86
87
# Plot data points
87
88
sns .scatterplot (
88
89
x = xs ,
89
90
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 ()))
91
96
92
97
# Plot each regression quantile
93
98
for i , p in enumerate (obj .take_regression_quantiles ().keys ()):
94
99
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 ] )
96
101
97
102
# Set title
98
103
ax .set_title (title )
@@ -132,7 +137,11 @@ def is_float(string):
132
137
ui .input_checkbox ("datePlotQ" , "Date axis" , value = True ),
133
138
ui .card (
134
139
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
+ ),
136
145
)
137
146
138
147
def server (input : Inputs , output : Outputs , session : Session ):
@@ -155,6 +164,7 @@ def distPlot():
155
164
date_plot = input .datePlotQ (),
156
165
template = template ,
157
166
data_color = data_color ,
167
+ palette = input .palette (),
158
168
background_color = '#1F1F1F' ,
159
169
point_size = 2 ,
160
170
width = 800 , height = 300 )
0 commit comments