Hi all, I’ve been toying with ridgeline plots (like demonstrated in the examples here: Violin Plots | Python | Plotly).
The adjustment I’ve been trying to make is to remove the transparency and to ensure that the z-order is appropriate (bottom:top :: front:back). This GitHub issue on z-ordering is relevant: feature request: z-ordering parameter for traces · Issue #2345 · plotly/plotly.py · GitHub.
I’ve got my immediate hacky solution here … just wondering if there’s a better way that I haven’t thought of yet or whether there’s something missing in the plotly api for this kind of thing. For this kind of graph, I definitely prefer it without the default transparency that violin plots come with, and z-ordering seems to be a little tricky at the moment (??)
Based off of the demo here:
import plotly.graph_objects as go
from plotly.colors import n_colors
import numpy as np
np.random.seed(1)
data = (np.linspace(1, 2, 12)[:, np.newaxis] * np.random.randn(12, 200) +
(np.arange(12) + 2 * np.random.random(12))[:, np.newaxis])
colors = n_colors('rgb(5, 200, 200)', 'rgb(200, 10, 10)', 12, colortype='rgb')
fig = go.Figure()
for i, (data_line, color) in enumerate(zip(data, colors)):
fig.add_trace(
go.Violin(x=data_line, line_color='black', name=i, fillcolor=color)
)
# use negative ... cuz I'm gonna flip things later
fig = fig.update_traces(orientation='h', side='negative', width=3, points=False, opacity=1)
# reverse the (z)-order of the traces
fig.data = fig.data[::-1]
# flip the y axis (negative violin is now positive and traces on the top are now on the bottom)
fig.update_layout(legend_traceorder='reversed', yaxis_autorange='reversed').show()
Produces …
I like it this way more … but it’s a bit fiddly to make!