更有温度的直方图
您之前为一家证券交易公司创建了直方图。他们认为现在生成的数据和图表过于冷冰冰。
他们希望在您最近创建的公司营收直方图上添加一句积极向上的话。
您正好有个主意——祝观众今天心情愉快,并用当前的星期几来呈现!
这里已经为您提供了一个 fig 直方图,您可以 show() 或 print() 一下,回忆它的样子。
本练习是课程的一部分
Python 中的 Plotly 数据可视化入门
练习说明
- 将注释放置在 x 轴中点处,y 轴的 95% 处。
- 为相对定位设置正确的
xref和yref值。 - 使用
update_layout()方法添加该注释。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()