Skip to content
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

QC Hospitalisations by age #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

mschoettle
Copy link
Collaborator

Adds weekly hospitalisations by age group (per 100k).
Hovering also shows the absolute number of new hospitalisations for that week.

Screen Shot 2021-12-10 at 06 40 04

mschoettle and others added 3 commits December 10, 2021 06:32
Places it next to MTL cases by age group figure.
Limited to the last 16 weeks in order to not overcrowd the figure.
Data is normalized to 100k per age group.
@jeremymoreau
Copy link
Owner

This looks great, thanks! Added range sliders like for the other figures (instead of limiting data to last 16 weeks):
screenshot1
screenshot2

Issues remaining:

  1. y-axis doesn't autoscale when adjusting range. There doesn't seem to be an way to do this. Manual zooming with the drag-to-zoom tool still works.
  2. Seems like the latest week of data isn't displayed anymore after adding the range slider.
  3. Might be nice to set a default range for the range slider (other than all) once there's a lot of data? Setting the rangeslider initial range - bug or user error? plotly/plotly.py#828 (comment)
  4. Is there a reason to display the week count? This seems arbitrary since it's just the number of weeks since data started being collected (and redundant with the date). I commented it out for now, but let me know if there is a reason I'm missing.

@mschoettle
Copy link
Collaborator Author

Thanks!

What I originally wanted to do is to start with an initial range of the last 16 weeks but because it does not zoom automatically the y-axis was too large and I ended up limiting it to the 16 weeks.
I don't even think that there is way to do this programmatically, right?

2. Seems like the latest week of data isn't displayed anymore after adding the range slider.

Is this for both figures? I think I removed the last 2 days of the hospitalization data because it is delayed and likely underreported.

4. Is there a reason to display the week count? This seems arbitrary since it's just the number of weeks since data started being collected (and redundant with the date). I commented it out for now, but let me know if there is a reason I'm missing.

The week number is the week number within the year. I added it because the data is weekly to show which week the data point corresponds to. But it could also just say "Week of yyyy-mm-dd".

@mschoettle
Copy link
Collaborator Author

1. y-axis doesn't autoscale when adjusting range. There doesn't seem to be an way to do this. Manual zooming with the drag-to-zoom tool still works.

I tried figure.update_layout(xaxis=dict(range=['2021-11-01', '2021-12-08']), yaxis=dict(range=[0, 20])) to test but unfortunately, contrary to the x-axis, the y-axis stays at the defined range.

Another problem with the range sliders is that there are added some additional empty dates at the beginning and end.

  1. Seems like the latest week of data isn't displayed anymore after adding the range slider.

Removing core.py line 304 (data_qc_age = data_qc_age.iloc[:-2]) might resolve this.

Manually sets the min/max date range for the mtl_age_fig and qc_age_fig to the earliest/latest dates in the dataset.
@jeremymoreau
Copy link
Owner

What I originally wanted to do is to start with an initial range of the last 16 weeks but because it does not zoom automatically the y-axis was too large and I ended up limiting it to the 16 weeks.
I don't even think that there is way to do this programmatically, right?

I tried figure.update_layout(xaxis=dict(range=['2021-11-01', '2021-12-08']), yaxis=dict(range=[0, 20])) to test but unfortunately, contrary to the x-axis, the y-axis stays at the defined range.

I tried searching for a solution, but it seems that it is not yet implemented in Plotly:
plotly/plotly.js#6958
https://community.plotly.com/t/autoscaling-the-y-axis-when-using-rangeslider/1456

Also some discussion for plotly.js (but not solved yet):
plotly/plotly.js#5544
plotly/plotly.js#1876

One possible solution could be to not use the Plotly rangeslider and instead use a Dash slider component outside the figure with a callback to redraw the Plotly figure, e.g. https://dash.plotly.com/basic-callbacks#dash-app-layout-with-figure-and-slider
Not the simplest solution though... so maybe we leave it as is for now with the manual zoom? Ideally Plotly would add the option, but I don't know if/when they will add it.

The week number is the week number within the year. I added it because the data is weekly to show which week the data point corresponds to. But it could also just say "Week of yyyy-mm-dd".

That makes sense! I removed it initially because the week count labels overlaped with the date labels on the x axis (when the number of date labels increases above a certain number). I think adding "Week of yyyy-mm-dd" in the hover template title is a good option. The title of the plots also says the data is weekly.

Is this for both figures? I think I removed the last 2 days of the hospitalization data because it is delayed and likely underreported.
Removing core.py line 304 (data_qc_age = data_qc_age.iloc[:-2]) might resolve this.

Yes, that was it! Removing the last 2 days hides the last week of data (so currently the MTL plot goes until Dec 6 while the QC hospitalisations fig goes to Nov 29 if the last 2 days are removed). Not sure which is best, commented it out for now so that both figures end on the same date.

Another problem with the range sliders is that there are added some additional empty dates at the beginning and end.

Not sure why those empty dates are being added (used the same function as all the other figures with a range slider), but manually setting the x axis range seems to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants