Plotly - добавление стрелки к оси x в области бумаги, возврат ошибки - PullRequest
1 голос
/ 06 августа 2020

Я пытаюсь нарисовать стрелку под 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 , стрелка не отображается.

Я пытался запустить этот пример с той же ошибкой.

1 Ответ

0 голосов
/ 07 августа 2020

Мне удалось добиться с помощью текста заголовка. Это также хороший пример для тех, кто хочет построить квадрант плотно:

 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,
                ))

        
...