Peter.k
Peter.k

Reputation: 1548

how to fit map to width with plotly (python)

I tried many of these sizing parameters from documentation: plotly documentation but nothing wants to cooperate with my browser under Jupyter.

I have a code:

layout = dict(
        title = 'city populations<br>(Click legend to toggle traces)',
        showlegend = True,
        geo = dict(
            scope='europe',
            resolution = 50,
            projection=dict( type='mercator' ),
            showland = True,
            landcolor = "rgb(217, 217, 217)",
            subunitcolor="rgb(255, 255, 255)",
            countrycolor="rgb(255, 255, 255)",
            lonaxis = dict( range= [ 14.0, 24.0 ] ),
            lataxis = dict( range= [ 49.0, 55.0 ] ),
            autosize=False,
            width=1000, height=1000,
            margin=dict( l=50, r=50, b=50, t=50, pad=4, autoexpand=True ),
            showrivers = True
        )
    )

and want to somehow set larger mapbox size but it's always the same (of about 30% of screen width). There's plenty of room in the browser. Why couldn't resize this window? It's all the time about 350x350 pixels.

Executive code:

fig = dict( data=cities, layout=layout )
py.iplot( fig, validate=False, update=True, resize=True )

Please give me some hint, because it's my first day with this wonderful tool.

EDIT: Now this works:

layout = dict(
        title = '2015 Poland city populations<br>(Click legend to toggle traces)',
        showlegend = True,
        autosize=False,
        width=1000, height=1000,
        margin=dict( l=50, r=50, b=50, t=50, pad=4, autoexpand=True ),
        geo = dict(
            scope='europe',
            resolution = 50,
            projection=dict( type='mercator' ),
            showland = True,
            landcolor = "rgb(217, 217, 217)",
            subunitcolor="rgb(255, 255, 255)",
            countrycolor="rgb(255, 255, 255)",
            lonaxis = dict( range= [ 14.0, 24.0 ] ),
            lataxis = dict( range= [ 49.0, 55.0 ] ),            
            showrivers = True
        )
    )

Upvotes: 1

Views: 2785

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31679

width and height must be key-value pairs in the layout dictionary, not in the geo dictionary (same as autosize and margin).

Try removing validate=False to get the warning messages from Plotly about those keys.

Upvotes: 2

Related Questions