How to properly change width and height of plotly.express.scattergeo() chart

Viewed 24

Good day,

I have a plotly.express.scattergeo() chart that I would like to resize. The map/chart currently looks like this: enter image description here

Here is the code:

import plotly.express as px
import pandas as pd

shape_boundary = gp.read_file('D:/Data/geoJSON/shape_boundary.json')

gdf = gp.GeoDataFrame.from_features(shape_boundary)
new_gdf = json.loads(gdf.to_json())


fig = px.scatter_geo(
    points_df,
    "y",
    "x",
    color="num_units",
    color_continuous_scale = 'Greys',
    range_color =[0, 600],
    labels={"num_units": "Number of Units"},
    fitbounds='locations'
)

fig.update_geos(
    showcoastlines=True,
    coastlinecolor="Black",
    showland=True,
    landcolor="White",
    showocean=True,
    oceancolor="LightBlue",
    projection_scale=9
)

fig.add_traces(
    px.scatter_geo(
        pd.DataFrame(
            new_gdf['features'][0]['geometry']['coordinates'][0], columns=["y", "x"]),
        "x",
        "y",
    )
    .update_traces(mode="lines", line_color="grey")
    .data
)


fig.show()

I need to change the width and height of the chart/map to look like this: enter image description here

But when I use

fig.update_layout(width=500, height=600)

I get this: enter image description here

How do I get the "canvas" to just resize to a square?

Any and all help is greatly appreciated. Thanks!

0 Answers
Related