MulaiMulai sekarang secara gratis

A happier histogram plot

The stock exchange firm you created the histogram for thinks that all the data and plots being created are too impersonal.

They have requested that a positive message be added to the histogram plot of company revenues you recently created.

You have just the right idea - you can wish the viewer a happy day and use the current day of the week for this!

There is a fig histogram available for you, feel free to show() or print() it to remind yourself what it looks like.

Latihan ini adalah bagian dari kursus

Introduction to Data Visualization with Plotly in Python

Lihat Kursus

Petunjuk latihan

  • Position the annotation halfway along the x-axis and 95% up the y-axis.
  • Set the correct values for xref and yref for relative positioning.
  • Use the update_layout() method to add the annotation.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Get and format today's date
today = datetime.today().strftime("%A")

# Create the message_annotation
message_annotation = dict(
  # Set the correct coordinates
  x=____, y=____, xref="____", yref="____",
  # Set the format of the text and box
  text=f"Have a Happy {today} :)",
  font=dict(size=20, color="white"),
  bgcolor="rgb(237, 64, 200)", showarrow=False
)

# Update the figure layout and show
fig.update_layout(annotations=[____])
fig.show()
Edit dan Jalankan Kode