Bar chart with `facet_row` only rendering data for one facet
See original GitHub issueI have a bar chart with a facet_row
defined as follows, with example data.
Example code and data for `facet_row` bug
tmp_data = [
{
"date": "2022-04-17",
"role_name": "Nurse",
"work_type": "Cleaning",
"daily_total_minutes": 45,
"percent_of_daily_role_total_minutes": 0.41,
},
{
"date": "2022-04-17",
"role_name": "Nurse",
"work_type": "Food preparation",
"percent_of_daily_role_total_minutes": 0.59,
},
{
"date": "2022-04-17",
"role_name": "Volunteer",
"work_type": "Cleaning",
"percent_of_daily_role_total_minutes": 0.26,
},
{
"date": "2022-04-17",
"role_name": "Volunteer",
"work_type": "Food preparation",
"percent_of_daily_role_total_minutes": 0.74,
},
{
"date": "2022-05-06",
"role_name": "Volunteer",
"work_type": "Food preparation",
"percent_of_daily_role_total_minutes": 1.0,
},
{
"date": "2022-05-07",
"role_name": "Volunteer",
"work_type": "Cleaning",
"percent_of_daily_role_total_minutes": 0.49,
},
{
"date": "2022-05-07",
"role_name": "Volunteer",
"work_type": "Food preparation",
"percent_of_daily_role_total_minutes": 0.51,
},
]
daily_work_by_caregiver_role_and_type_with_percent_chart = px.bar(
tmp_data,
x="date",
y="percent_of_daily_role_total_minutes",
facet_row="role_name",
color="work_type",
title=_("Daily work percent by caregiver role and work type"),
labels={
"role_name": _("Caregiver role"),
"percent_of_daily_role_total_minutes": _("Work percent"),
"work_type": _("Type of work"),
},
text_auto=True,
)
daily_work_by_caregiver_role_and_type_with_percent_chart.layout.yaxis.tickformat = ",.0%"
# render the chart
daily_work_by_caregiver_role_and_type_with_percent_chart.to_html()
When rendering the chart, the x axis correctly determines the data are dates and the y-axis on the bottom facet is correctly formatted as a percentage with the data rendering. However, the top facet doesn’t render any data.
I have tried both with and without specifying the yaxis.tickformat
and get a similar result, where the first facet series doesn’t render any data.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Compound Charts: Layer, HConcat, VConcat, Repeat, Facet
Like repeated charts, Faceted charts provide a more convenient API for creating multiple views of a dataset for a specific type of chart:...
Read more >Facet and trellis plots in Python - Plotly
Facet plots, also known as trellis plots or small multiples, are figures made up of multiple subplots which have the same set of...
Read more >fct_reorder() only working properly for one facet - Stack Overflow
I am trying to create a faceted bar graph ...
Read more >The seaborn.objects interface — seaborn 0.12.1 documentation
Specifying a plot and mapping data#. The objects interface should be imported with the following convention: import seaborn.objects as ...
Read more >Introducing Plotly Express - Medium
If you want a basic scatter plot, it's just px.scatter(data, x="column_name", y="column_name") . Here's an example with the Gapminder dataset – which comes ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So what’s happening here is that the upper facet has only one day’s worth of data in it, and the automatic calculation of the bar width results in a single extremely thin bar being shown around midnight of April 17 (the bar is less than a millisecond wide). This is pretty counter-intuitive but that’s what’s happening. You can force the bars to be one day wide by calling
.update_traces(width=24*60*60*1000)
on the figure.@alexcjohnson I can see this being more or less reasonable behaviour for a single subplot, but for
match
ed axes, I could also see the bar width being computed while taking into account all bars on the whole set of axes, no?Great, happy I was able to help, sorry for the friction you’ve been encountering 😃