-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Single bar datum does not display with barmode='overlay' #2191
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
Comments
Can you at least share a reproducible python example? Debugging from screenshots is very hard. Thanks. |
This is probably covered by #1308 and #1346 - the issue is that with no other information (such as a second bar) to provide a scale we can't figure out a reasonable width automatically. So we default to 1, which for dates means 1 millisecond (so your single bar probably is being displayed, just invisibly thin). I suppose 1 day might be more useful as a default (it would work for you anyway) but I don't think it's appropriate to use the axis range as part of the default logic, that would make the meaning of the trace dependent on how you happen to be viewing it (zoom). Normally in overlay mode we don't allow subsequent bar traces to influence each other, because comparing traces with differing bar widths is an important use case for overlay mode. I suppose we could make an exception for single-bar traces, but the cleanest solution is to use the |
Here's a Dash example: from datetime import date
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
data = [(date(2017, 11, 4), 9, 1),
(date(2017, 11, 5), 8, 1),
(date(2017, 11, 11), 12, 1),
(date(2017, 11, 12), 9, 2)
]
data = pd.DataFrame(data, columns=['Date', 'Metric', 'Category'])
def generate_graph(data, barmode='overlay'):
data1 = data[data['Category']==1]
data2 = data[data['Category']==2]
graph_data1 = go.Bar(x=data1['Date'],
y=data1['Metric'],
hoverinfo='x+y'
)
graph_data2 = go.Bar(x=data2['Date'],
y=data2['Metric'],
hoverinfo='x+y'
)
layout = go.Layout(barmode=barmode,
title=barmode)
return go.Figure(data=[graph_data1, graph_data2], layout=layout)
app = dash.Dash()
app.layout = html.Div([dcc.Graph(id='overlay', figure=generate_graph(data, barmode='overlay')),
dcc.Graph(id='relative', figure=generate_graph(data, barmode='relative'))
])
if __name__ == '__main__':
app.run_server(debug=True) |
@radumas from the fact that half a day showed up in autorange for the overlay graph it definitely looks like you've got a 1-ms-wide bar there. Did you try my suggestion of adding an explicit width to the orange trace? I guess if you go that route you need to explicitly account for the gap, which by default is 20%, so it would be |
Ah, no I just used the |
OK. Closing as this does seem covered by the other two issues I mentioned. |
This was originally a
plotly.py
issue I was told to reopen here. Forgive the lack ofjs
reproducible exampleI'm creating a bar plot with multiple categories and I wanted to colour each category differently, even though the categories don't overlap. Multiple rows display fine using
barmode='overlay'
, but if there's only one row in a category, it doesn't display:If I don't split the data, it displays fine (different street, same issue):
If I change

barmode='relative'
then it displays fine:The text was updated successfully, but these errors were encountered: