{
"cells": [
{
"cell_type": "markdown",
"id": "860a082c",
"metadata": {},
"source": [
"# Plotly 水平线、垂线和矩形\n",
"\n",
"参考:[Horizontal and Vertical Lines and Rectangles | Python | Plotly](https://plotly.com/python/horizontal-vertical-shapes/)\n",
"\n",
"*在 plotly 4.12 中引入*\n",
"\n",
"可以通过 `plotly.graph_objects.Figure` 的 `add_hline`, `add_vline`, `add_hrect`, 和 `add_vrect` 方法添加横跨整个 plot 的水平线、垂线和矩形。这些形状固定在一个轴的端点上,而不管绘图的范围如何,固定在另一个轴上的数据坐标上。下面展示了一些可能性,尝试平移和缩放结果图,看看形状如何粘在一些轴上:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3f5c7860",
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objects as go\n",
"go.FigureWidget(); # 初始化"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9a58675c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "petal_length=%{x}
petal_width=%{y}