Get startedGet started for free

Annotating your savings

You have been working hard over the last 30 weeks to build your savings balance for your first car. However, there is some extra context that 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.

For both annotations:

  • Ensure the arrow is showing and the head of the arrow is size 4
  • Make the font black color using the string ('black'), not RGB method.

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

This exercise is part of the course

Introduction to Data Visualization with Plotly in Python

View Course

Exercise instructions

  • Create the loss_annotation at week 10 (savings 400) with text 'Urgent House Repairs'.
  • Create the gain_annotation at week 18 (savings 2500) with text 'New Job!'.
  • For both annotations, set the arrow to be showing, the arrowhead size to 4, and the text color to black using the string, not RGB color.
  • Add both annotations to the fig using update_layout().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the first annotation
loss_annotation = {'x': ____, 'y': ____, 'showarrow': ____, 'arrowhead': ____,
                    'font': {'color': '____'}, 'text': ____}

# Create the second annotation
gain_annotation = {'x': ____, 'y':____, 'showarrow': ____, 'arrowhead': ____,
                    'font': {'color': '____'}, 'text': ____}

# Add annotations to the figure
fig.update_layout({____: [____]})

# Show the plot!
fig.show()
Edit and Run Code