question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add continuous color scale to strip, box, and violin plots

See original GitHub issue

Currently, strip/box/violin plots only work with categorical/discrete colormaps. This is sufficient for the violins and boxes but for the points that can be included in all three plots, it would be useful to color by a continuous feature and to add a colorbar to the plot. I looked around a bit and it seems like the go.Box constructor needs to have the coloraxis attrbute added to it (and I suspect something would need to be added to avoid coloring the boxes/violins in the same colors as the points, since they are colored the same for categorical variables).

The example below illustrates the issue by trying to color by the sepal_width variable:

import plotly.express as px

iris = px.data.iris()
px.strip(iris, 'species', 'sepal_length', 'sepal_width', stripmode='overlay')

image

The resulting plot is not meaningful since it colors a continuous variable with a discrete colormap.

So far, I have not found a prettier workaround that this (which is imperfect since it uses the legend instead of a colorbar):

import matplotlib as mpl

sw = iris['sepal_width'].sort_values()
sw_01 = (sw - sw.min()) / (sw.max() - sw.min())
sw_colors = {n: mpl.colors.rgb2hex(c) for n, c in zip(sw, mpl.cm.viridis(sw_01))}
px.strip(iris, 'species', 'sepal_length', 'sepal_width',
         stripmode='overlay', category_orders={'sepal_width': sw.to_list()[::-1]},
         color_discrete_map=sw_colors)

image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dandolodavidcommented, Apr 14, 2022

Hello! The same is for me. I’m trying to create a new feature importance visualization and I will need this. Hoper there will be a fix soon. Thanks

1reaction
ethantenisoncommented, Mar 31, 2022

This feature would be helpful; I’m trying to replicate a summary plot for SHAP values, and I have not been able to do it.

Same! It’s a shame.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ggplot2 violin plot : Quick start guide - Data Visualization
Prepare the data · Basic violin plots · Add summary statistics on a violin plot · Violin plot with dots · Change violin...
Read more >
A Complete Guide to Violin Plots | Tutorial by Chartio
Violin plots are used to compare the distribution of data between groups. Learn how violin plots are constructed and how to use them...
Read more >
Violin Plots 101: Visualizing Distribution and Probability Density
The box plot is an old standby for visualizing basic distributions. It's convenient for comparing summary statistics (such as range and ...
Read more >
Visualizing Distributions
Histograms. Density plots. Box plots. Violin plots. Swarm plots. Density ridges. Strip Plots. Strip Plot Basics.
Read more >
Visualizing Distributions with Raincloud Plots (and How to ...
A suitable chart hybrid, consisting of a combination of box plots, violin plots, and jittered points, is called a raincloud plot.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found