plotly / plotly/plotly.js

showframe not working for scattergeo if geo.scope is set

Aperta
#7,051 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
JavaScript
Stelle
18.3k
Fork
2k
Merge medio
2g 12h
PR unite (30g)
28

Descrizione

Expect that when showframe=True that there's a border around the map.

To Reproduce:

from dash.dash import PreventUpdate
import xarray as xr
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import requests
from datetime import datetime, timedelta
from dash import Dash, dcc, html, Input, Output, State, callback, dash_table

# Create a sample dataframe
np.random.seed(42)  # For reproducibility
data_size = 500

data_1041 = pd.DataFrame({
    'latitude': np.random.uniform(low=10.0, high=35.0, size=data_size),
    'longitude': np.random.uniform(low=-91.0, high=-55.0, size=data_size)
})

app = Dash(__name__)
server = app.server

def blank_fig():
    fig = go.Figure(go.Scatter(x=[], y=[]))
    fig.update_layout(template=None)
    fig.update_xaxes(showgrid=False, showticklabels=False, zeroline=False)
    fig.update_yaxes(showgrid=False, showticklabels=False, zeroline=False)
    
    return fig

color_sequence = ['#2E91E5', '#E15F99', '#1CA71C', '#FB0D0D', '#DA16FF', '#222A2A', '#B68100', '#750D86', '#EB663B', '#511CFB', '#00A08B', '#FB00D1', '#FC0080', '#B2828D', '#6C7C32', '#778AAE', '#862A16', '#A777F1', '#620042', '#1616A7', '#DA60CA', '#6C4516', '#0D2A63', '#AF0038']

app.layout = html.Div(
    [
        dcc.Dropdown(
            options=['1041'],
            value=['1041'],
            multi=True,
            id='dropdown-drone-choice'
        ),
        html.Div([dcc.Graph(id='saildrone-map', figure=blank_fig(), style={'width': '90vw', 'height': '90vh'})])
    ],
    style={"margin": "1em 5em", "font": "Times New Roman"}
)

@app.callback(
    Output('saildrone-map', 'figure'),
    Input('dropdown-drone-choice', 'value')
)
def update_drone(droneid_nam):
    dronedata_all = {
        '1041': data_1041,
    }

    fig = go.Figure()
    for i, drone in enumerate(droneid_nam):
        fig.add_trace(go.Scattergeo(
            lat=dronedata_all[drone]['latitude'][-180:],
            lon=dronedata_all[drone]['longitude'][-180:],
            name=drone,
            mode='markers',
            marker=dict(
                color=color_sequence[i]
            ),
            showlegend=True
        ))
        fig.add_trace(go.Scattergeo(
            lat=[dronedata_all[drone]['latitude'].iloc[-1]],
            lon=[dronedata_all[drone]['longitude'].iloc[-1]],
            name=drone,
            mode='markers',
            marker=dict(
                symbol='x',
                size=8,
                color=color_sequence[i],
                line=dict(
                    color='black',
                    width=1
                )
            ),
            showlegend=False
        ))

    fig.update_layout(
        geo=dict(
            scope='north america',
            showframe=True,
            showland=True,
            landcolor='rgb(204, 204, 204)',
            projection_type='mercator',
            lonaxis=dict(
                showgrid=True,
                gridwidth=0.5,
                gridcolor='gray',
                range=[-91.0, -55.0],
                dtick=5
            ),
            lataxis=dict(
                showgrid=True,
                gridwidth=0.5,
                gridcolor='gray',
                range=[10.0, 35.0],
                dtick=5
            )
        ),
        legend=dict(
            title='droneID',
            bordercolor='black',
            borderwidth=1
        ),
        font=dict(
            family='Times New Roman',
            size=16
        ),
        margin=dict(
            l=20, r=20, t=20, b=20
        )
    )

    dtick = 5
    x = list(range(-90, -55 + dtick, dtick))
    y = list(range(10, 40 + dtick, dtick))
    xpos = -90
    ypos = 10
    fig.add_trace(go.Scattergeo(
        lon=x[1:-1] + [xpos] * (len(y) - 2),
        lat=[ypos] * (len(x) - 2) + y[1:-1],
        showlegend=False,
        text=x[1:-1] + y[1:-1],
        mode='text',
        hoverinfo='skip'
    ))

    return fig

if __name__ == "__main__":
    app.run_server(debug=True)

Produces:
Screen Shot 2024-07-16 at 4 43 14 PM

Workaround:
Get rid of scope='north america', and the frame will appear with and without showframe defined

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo la riproduzione Scattergeo fornita e confronta la mappa renderizzata con e senza geo.scope impostato su "north america". Segui il percorso di rendering del frame geo in plotly.js, quindi verifica che showframe=True produca il bordo previsto quando è configurato uno scope e che il workaround esistente non sia più necessario.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.