Skip to content

[BUG]: fitbounds="locations" thinks the world is flat and goes through longitude zero when dealing with positive and negative longitudes #5539

@rl-utility-man

Description

@rl-utility-man

Description

The Scatter_geo fitbounds='locations' parameter is supposed to show just the relevant part of the world. When the points are on both sides of longitude +/-180, it includes longitude zero on the map even if a map that shows longitude 180 would be far more compact. The two maps below are trivially different; when the eastern most coordinate is 179, the map is compact and fitbounds works as expected. When the eastern most coordinate is -179, the map includes a large amount of unnecessary, blank geography.

Specifying longitude and latitude ranges manually is a workaround.

Let me know if this would be a good PR for someone new to the codebase

Screenshots/Video

Image Image

Steps to reproduce

Run this code

import plotly.graph_objects as go
for lon in [-179, 179]:
    # Coordinates for the points
    lats = [43.1155, 32.7157]
    lons = [131.8855, lon]

    fig = go.Figure(go.Scattergeo(
        lat=lats,
        lon=lons,
        mode='markers+text',
        textposition='top center',
        marker=dict(size=10, color='red')
    ))

    fig.update_layout(
        title=f'eastern most longitude is {lon}',
        geo=dict(
            fitbounds="locations",
            visible=True,
            projection_type='equirectangular'

        )
    )

    fig.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions