Refer to FigureFactory.create_violin() for docstring. Returns fig for violin plot with colorscale.
(
data,
data_header,
group_header,
colors,
use_colorscale,
group_stats,
rugplot,
sort,
height,
width,
title,
)
| 259 | |
| 260 | |
| 261 | def violin_colorscale( |
| 262 | data, |
| 263 | data_header, |
| 264 | group_header, |
| 265 | colors, |
| 266 | use_colorscale, |
| 267 | group_stats, |
| 268 | rugplot, |
| 269 | sort, |
| 270 | height, |
| 271 | width, |
| 272 | title, |
| 273 | ): |
| 274 | """ |
| 275 | Refer to FigureFactory.create_violin() for docstring. |
| 276 | |
| 277 | Returns fig for violin plot with colorscale. |
| 278 | |
| 279 | """ |
| 280 | |
| 281 | # collect all group names |
| 282 | group_name = [] |
| 283 | for name in data[group_header]: |
| 284 | if name not in group_name: |
| 285 | group_name.append(name) |
| 286 | if sort: |
| 287 | group_name.sort() |
| 288 | |
| 289 | # make sure all group names are keys in group_stats |
| 290 | for group in group_name: |
| 291 | if group not in group_stats: |
| 292 | raise exceptions.PlotlyError( |
| 293 | "All values/groups in the index " |
| 294 | "column must be represented " |
| 295 | "as a key in group_stats." |
| 296 | ) |
| 297 | |
| 298 | gb = data.groupby([group_header]) |
| 299 | L = len(group_name) |
| 300 | |
| 301 | fig = make_subplots( |
| 302 | rows=1, cols=L, shared_yaxes=True, horizontal_spacing=0.025, print_grid=False |
| 303 | ) |
| 304 | |
| 305 | # prepare low and high color for colorscale |
| 306 | lowcolor = clrs.color_parser(colors[0], clrs.unlabel_rgb) |
| 307 | highcolor = clrs.color_parser(colors[1], clrs.unlabel_rgb) |
| 308 | |
| 309 | # find min and max values in group_stats |
| 310 | group_stats_values = [] |
| 311 | for key in group_stats: |
| 312 | group_stats_values.append(group_stats[key]) |
| 313 | |
| 314 | max_value = max(group_stats_values) |
| 315 | min_value = min(group_stats_values) |
| 316 | |
| 317 | for k, gr in enumerate(group_name): |
| 318 | vals = np.asarray(gb.get_group(gr)[data_header], float) |
no test coverage detected