我在我的烧瓶应用程序中渲染了一个情节时间表。我创建了以下代码以在相应刻度的 y 坐标处向我的图表添加水平线。现在,这些线被添加到每个条的中心。我想调整位置以改为在条形图的顶部绘制。
yanchor
属性不起作用。我还有其他方法可以实现这一目标吗?
这是我的街区:
# Get the ticktext and tickvals from the y-axis
ticktext = fig.layout.yaxis.ticktext
tickvals = fig.layout.yaxis.tickvals
# Create a dictionary that maps each ticktext to its corresponding y-coordinate,
# but only for ticktext values that are not equal to " "
y_coord = {ticktext[i]: tickvals[i] for i in range(len(ticktext)) if ticktext[i] != " "}
# Loop through each product in the product list
for product in product_list:
# Get the corresponding y-coordinate from the y_coord dictionary
try:
y = y_coord[product]
except:
continue
fig.add_hline(y=y, line_dash="dash", line_width=2, line_color="gray", yanchor="top")