Rotate plotly figure to lat long

Viewed 306

I am plotting some data on a globe view using plotly. For example

import plotly.graph_objects as go
import numpy as np
fig = go.Figure(go.Scattergeo(lat=np.linspace(37.5, 47, 10),
                              lon=np.linspace(-84, 2, 10)))
fig.update_geos(projection_type='orthographic')
fig.show()

this will generate the figure below

default view

I would like to rotate the view to specify the lat/lon to "look at". For example this may be the midpoint of the data I am concerned about.

rotated view

What can I update about the figure's layout to specify a lat/long to focus on?

1 Answers

Just include:

fig.update_geos(projection_rotation = {'lat': 43.83, 'lon': -36.22, 'roll': 0})

Plot 1:

enter image description here

I've run into cases where setting these attributes will mess up the zoom. For example:

fig.update_geos(projection_type='orthographic',
                projection_rotation = {'lat': 37.5, 'lon': -84, 'roll': 0},
               )

Plot 2

enter image description here

I'm not sure why, but you can just include:

projection_scale = 0.5

And you'll get this again:

Plot 3

enter image description here

Complete code:

import plotly.graph_objects as go
import numpy as np
fig = go.Figure(go.Scattergeo(lat=np.linspace(37.5, 47, 10),
                              lon=np.linspace(-84, 2, 10)))
f = fig.full_figure_for_development(warn=False)

fig.update_geos(projection_type='orthographic',
                projection_rotation = {'lat': 43.83, 'lon': -36.22, 'roll': 0})

fig.show()

Here's an alternative setup using dicts that avoids repeating "projection" so many times:

fig.layout.geo.projection = {'rotation': {'lat': 37.5, 'lon': -84},
                             'scale': 0.5,
                             'type': 'orthographic'}
Related