Aan de slagGa gratis aan de slag

Annotating your savings

You have worked hard over the last 30 weeks to build your savings balance for your first car. However, some extra context needs to be added to explain a drop in savings and, later, a big increase in savings accumulated each fortnight.

Your task is to annotate the bar chart of your savings balance over the weeks and add two key annotations to the plot to explain what happened.

A figure fig has already been created using a savings DataFrame (with x as Week) for you.

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with Plotly in Python

Cursus bekijken

Oefeninstructies

  • Create the loss_annotation at week 10 (savings 400) with the text "Urgent House Repairs".
  • Create the gain_annotation at week 18 (savings 2500) with the text "New Job".
  • Add both annotations to the fig using update_layout().

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create the first annotation
loss_annotation = dict(
    x=____, y=____, text="____",
    font=dict(color="black"), showarrow=True, arrowhead=4
)

# Create the second annotation
gain_annotation = dict(
    x=____, y=____, text="____",
    font=dict(color="black"), showarrow=True, arrowhead=4,
)

# Add annotations to the figure
fig.update_layout(annotations=[____, ____])

# Show the plot
fig.show()
Code bewerken en uitvoeren