Add an horizontal line to an existent chart
See original GitHub issueHello, I am using chime project to simulate some numbers to a local hospital and I would like to add a line with the maximum hospital capacity that will work as a threshold. For that I need to add a horizontal line, i.e, y=100
to this chart. I am having an hard time doing it, though.
What would be the best approach to do this?
Kind regards
def build_census_chart(
*,
alt,
census_df: pd.DataFrame,
max_y_axis: Optional[int] = None,
hospital_maximum_capacity: Optional[int] = None,
) -> Chart:
"""Build census chart."""
y_scale = alt.Scale()
if max_y_axis:
y_scale.domain = (0, max_y_axis)
x = dict(shorthand="date:T", title="Date", axis=alt.Axis(format=(DATE_FORMAT)))
y = dict(shorthand="value:Q", title="Census", scale=y_scale)
color = "key:N"
tooltip = ["date:T", alt.Tooltip("value:Q", format=".0f", title="Census"), "key:N"]
# TODO fix the fold to allow any number of dispositions
points = (
alt.Chart()
.transform_fold(fold=["hospitalized", "icu", "ventilated"])
.encode(x=alt.X(**x), y=alt.Y(**y), color=color, tooltip=tooltip)
.mark_line(point=True)
)
bar = (
alt.Chart()
.encode(x=alt.X(**x))
.transform_filter(alt.datum.day == 0)
.mark_rule(color="black", opacity=0.35, size=2)
)
'''bar = (
alt.Chart()
.encode(y=alt.Y(**y))
.transform_filter(alt.datum.day == 0)
.mark_rule(color="red", opacity=0.35, size=2)
)'''
return alt.layer(points, bar, data=census_df)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Add a Horizontal Line to an Excel Chart - Peltier Tech
Right click on the added series, and change its chart type to XY Scatter With Straight ...
Read more >How to Add a Horizontal Line in a Chart in Excel
Add a Horizontal Target Line in Column Chart · Go to → Fill & Line → Line. · Change line style to “No...
Read more >How to add horizontal line to chart - Get Digital Help
Select the chart. Go to tab "Design"; Add the "Primary Vertical" axis; Double press with left mouse button on axis values to open...
Read more >How to add a line in Excel graph: average line, benchmark, etc.
Insert a new column beside your source data. · Right-click the existing graph, and choose Select Data… from the context menu: · In...
Read more >How to add a horizontal line to the chart - Microsoft Excel 2016
Under Chart Tools, on the Design tab, in the Data group, choose Select Data: Select Data in Excel 2016 · Right-click in the...
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
The best way to do this is with a rule mark:
Note that in the next version of Altair (4.2) this will be slightly easier using the datum encoding; the horizontal line will look something like this:
(The final API has not been decided yet)
Yes, for example, use