Utility function for _contour_trace Adds the background color to fill gaps outside of computed contours. To compute the background color, the color of the contour with largest area (``val_outer``) is used. As background color, we choose the next color value in the direction of
(
all_contours,
all_values,
all_areas,
all_colors,
values,
val_outer,
v_min,
v_max,
colors,
color_min,
color_max,
)
| 319 | |
| 320 | |
| 321 | def _add_outer_contour( |
| 322 | all_contours, |
| 323 | all_values, |
| 324 | all_areas, |
| 325 | all_colors, |
| 326 | values, |
| 327 | val_outer, |
| 328 | v_min, |
| 329 | v_max, |
| 330 | colors, |
| 331 | color_min, |
| 332 | color_max, |
| 333 | ): |
| 334 | """ |
| 335 | Utility function for _contour_trace |
| 336 | |
| 337 | Adds the background color to fill gaps outside of computed contours. |
| 338 | |
| 339 | To compute the background color, the color of the contour with largest |
| 340 | area (``val_outer``) is used. As background color, we choose the next |
| 341 | color value in the direction of the extrema of the colormap. |
| 342 | |
| 343 | Then we add information for the outer contour for the different lists |
| 344 | provided as arguments. |
| 345 | |
| 346 | A discrete colormap with all used colors is also returned (to be used |
| 347 | by colorscale trace). |
| 348 | """ |
| 349 | # The exact value of outer contour is not used when defining the trace |
| 350 | outer_contour = 20 * np.array([[0, 0, 1], [0, 1, 0.5]]).T |
| 351 | all_contours = [outer_contour] + all_contours |
| 352 | delta_values = np.diff(values)[0] |
| 353 | values = np.concatenate( |
| 354 | ([values[0] - delta_values], values, [values[-1] + delta_values]) |
| 355 | ) |
| 356 | colors = np.concatenate(([color_min], colors, [color_max])) |
| 357 | index = np.nonzero(values == val_outer)[0][0] |
| 358 | if index < len(values) / 2: |
| 359 | index -= 1 |
| 360 | else: |
| 361 | index += 1 |
| 362 | all_colors = [colors[index]] + all_colors |
| 363 | all_values = [values[index]] + all_values |
| 364 | all_areas = [0] + all_areas |
| 365 | used_colors = [color for color in colors if color in all_colors] |
| 366 | # Define discrete colorscale |
| 367 | color_number = len(used_colors) |
| 368 | scale = np.linspace(0, 1, color_number + 1) |
| 369 | discrete_cm = [] |
| 370 | for i, color in enumerate(used_colors): |
| 371 | discrete_cm.append([scale[i], used_colors[i]]) |
| 372 | discrete_cm.append([scale[i + 1], used_colors[i]]) |
| 373 | discrete_cm.append([scale[color_number], used_colors[color_number - 1]]) |
| 374 | |
| 375 | return all_contours, all_values, all_areas, all_colors, discrete_cm |
| 376 | |
| 377 | |
| 378 | def _contour_trace( |