-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scattermode = group #4913
Comments
From @TonyBonen asking for this feature in #5480: I want to have a plot with scatter points overtop of bars. The problem is that the locations (on the x axis in my case) of the bars cannot be passed to the scatter points - they always sit directly above the x-axis values rather than being spread out across the bars within a grouped category. Its the same issue as being asked here: https://stackoverflow.com/questions/54591377/overlay-a-grouped-bar-chart-with-scatter-in-plotly I'm working in R plotly but seems this problem appears also in the Python implementation. This example should produce the error:
The result is something like the screen shot below where in the 2 groups (men and women) the 3 scatter points are lined up in the middle of the group. The desired behaviour is to have those points appear above their respective colour/country groups. |
As a workaround for now, one can use a carefully-configured Here is the annotated Python code for generating this figure, which should be reasonably easy to translate to R: import plotly.graph_objects as go
fig = go.Figure(
data=[
go.Bar(x=["a","b"], y=[1,2]),
go.Bar(x=["a","b"], y=[2,1]),
go.Box(x=["a","b"], y=[0.5,1.5],
marker_color="red"), # marker_color required
go.Box(x=["a","b"], y=[1.5,0.5],
marker_color="green"), # marker_color required
],
layout=dict(
hovermode="closest", #otherwise you get the box hovers
barmode="group",
bargroupgap=0, # the default
bargap=0.2, # the default
boxmode="group",
boxgroupgap=0, # set to match bargroupgap
boxgap=0.2, # set to match bargap,
template="none"
)
)
fig.update_traces(
selector=dict(type="box"), # update only boxes
boxpoints="all", # show points
pointpos=0, # centered
jitter=0, # no jitter
line_color="rgba(255,255,255,0)", # hide box lines
fillcolor="rgba(255,255,255,0)" # hide box fill
)
fig.show() |
How could this work with the x axis values being |
Wondering if should add points to the |
Let’s keep it in the scatter trace. We still want to support other features of scatter traces like error bars, lines… and it’s often going to be a different data set from the associated bars, perhaps on a different y axis. |
It looks we also need to add |
We need to be able to position
scatter
markers (notscattergl
!) on top of bars even whenbarmode=group
. Note: the ability to position scatter markers on top of grouped, stacked bars is out of scope.This means we will need to port the following attributes from
bar
toscatter
:alignmentgroup
offsetgroup
We will also need to create new layout attributes for
scatter
, with behaviour ported frombar
:scattermode
(accepting only group and overlay, which is the current default)scattergap
The text was updated successfully, but these errors were encountered: