我正在尝试使用以下代码在x_axis下方绘制箭头:
myplot = go.Figure(data=go.Scatter(x=df['time'], y=df['count'], mode='markers'))
xstart = -2
xmax = 3.5
xmin = -3.5
padding = 0.05
ypos = -0.1
mylplot.update_layout(
plot_bgcolor=colors['backgraph'],
paper_bgcolor=colors['backpaper'],
font_color=colors['text'],
showlegend=False,
width=550,
height=550,
xaxis=dict(title_text="Time", showgrid=False, showticklabels=False),
yaxis=dict(title_text="Counts", showgrid=False, showticklabels=False),
annotations=[dict(
x=xmin,
y=ypos,
ax=xstart + padding,
ay=ypos,
xref='x',
axref='x',
yref='paper',
ayref='paper',
showarrow=True,
arrowhead=2,
arrowsize=1,
arrowwidth=3,
arrowcolor='#0000ff',
)],
但是我收到以下错误:
ValueError:
Invalid value of type 'builtins.str' received for the 'ayref' property of layout.annotation
Received value: 'paper'
The 'ayref' property is an enumeration that may be specified as:
- One of the following enumeration values:
['pixel']
- A string that matches one of the following regular expressions:
['^y([2-9]|[1-9][0-9]+)?$']```
如果将ayref设置为y,则箭头不会显示。
我尝试运行this example,但出现相同的错误。
答案 0 :(得分:0)
我能够使用标题文本。这也是谁希望在情节中建立象限的一个很好的例子:
quadplot = px.scatter(df, x="time", y ="count", hover_name="name", color="status", hover_data="name", color_discrete_map=color_discrete_map)
#there is a small offset adjustment in order to be in the center.
xm = (df['time'].max()/2) + ((df['time'].max()/100)*3)
ym = (df['count'].max()/2) + ((df['count'].max()/100)*3)
xf = df['time'].max()
yf = df['count'].max()
quadplot.update_layout(
plot_bgcolor=colors['b'],
paper_bgcolor=colors['ba'],
font_color=colors['text'],
showlegend=False,
width=550,
height=550,
xaxis=dict(title_text="(-) «───────── Time ─────────» (+)", showgrid=False, showticklabels=False, rangemode='tozero', mirror=True, linecolor=colors['line'], linewidth=2),
yaxis=dict(title_text="(-) «───────── Count ─────────» (+)", showgrid=False, showticklabels=False, rangemode='tozero', mirror=True, linecolor=colors['line'], linewidth=2),
shapes=[dict(
type='line',
yref = 'paper', y0=0, y1=1,
xref = 'x', x0=xm, x1=xm,
line=dict(
color=colors['line'],
width=2,
),
)])
quadplot.add_shape(
type='line',
yref = 'y', y0=ym, y1=ym,
xref = 'paper', x0=0, x1=1,
line=dict(
color=colors['line'],
width=2,
))