LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Introduction to Data Visualization with Plotly in Python

Kurs anzeigen

Anleitung zur Übung

  • 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().

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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 bearbeiten und ausführen