Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Color a group of individual points in boxplot

Hello,

Is there a way to change colour for a group of specific points in the box plot?
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
with z= [16,20.9,0.75, 10.25] marked as red, others got marked as blue.

Which attributes of ‘box’ will be best to use in this case?

[‘boxmean’, ‘boxpoints’, ‘customdata’, ‘customdatasrc’, ‘fillcolor’,
‘hoverinfo’, ‘hoverinfosrc’, ‘hoverlabel’, ‘hoveron’, ‘ids’, ‘idssrc’,
‘jitter’, ‘legendgroup’, ‘line’, ‘marker’, ‘name’, ‘notched’,
‘notchwidth’, ‘opacity’, ‘orientation’, ‘pointpos’, ‘selected’,
‘selectedpoints’, ‘showlegend’, ‘stream’, ‘text’, ‘textsrc’, ‘type’,
‘uid’, ‘unselected’, ‘visible’, ‘whiskerwidth’, ‘x’, ‘x0’, ‘xaxis’,
‘xcalendar’, ‘xsrc’, ‘y’, ‘y0’, ‘yaxis’, ‘ycalendar’, ‘ysrc’]

Thanks,

Current code:

trace0 = go.Box(
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
name = “All Points”,
jitter = 0.3,
pointpos = -1.8,
boxpoints = ‘all’,
marker = dict(
color = ‘rgb(7,40,89)’),
line = dict(
color = ‘rgb(7,40,89)’)
)

data = [trace0]

layout = go.Layout(
title = “Box Plot Styling Outliers”
)

fig = go.Figure(data=data,layout=layout)
plot4_url = iplot(fig)

You can subscribe to https://github.com/plotly/plotly.js/issues/2308 for the most up-to-date development info.

Thanks etienne,
I found the answer by using ‘selectedpoints’ attribute.

alist= [-2.2391868449, -0.27694127080000003, -0.9704516304, -0.5314255407, -12.5996875292, -3.9869494182, -3.7308684248, 0.1038640625, -9.6580723325, -10.8100515604, 5.9898277385, -1.1549821991, -6.0922951791, -0.9952458862, -7.6610241667]
outlier_value = -12.5996875292
apos = alist.index(outlier_value)

trace0 = go.Box(
y = alist,
name = “All Points”,
#jitter = 0.3,
pointpos = -2,
opacity = 1,
boxpoints = ‘all’,
selectedpoints = [apos],
marker = dict( color = ‘brown’, opacity = 4),
line = dict(color = ‘rgb(7,40,89)’)
)

data = [trace0]

layout = go.Layout(
title = “Box Plot Styling Outliers”
)

fig = go.Figure(data=data,layout=layout)
plot4_url = iplot(fig)