GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing github.com — Fix bad default zoom in Plotly Express map functions by emilykl · Pull Request #5686 · plotly/plotly.py Conversation
|
| Before | After |
|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Code:
import json from urllib.request import urlopen import pandas as pd import plotly.express as px # px.scatter_map() df = pd.DataFrame( { "city": ["San Marino", "Chicago", "Nairobi", "Istanbul", "Trondheim"], "lat": [43.9360958, 41.85003, -1.28333, 41.01384, 63.43049], "lon": [12.4417702, -87.65005, 36.81667, 28.94966, 10.39506], } ) fig = px.scatter_map(df, lat="lat", lon="lon") fig.update_layout( title_text="px.scatter_map()", title_font_size=18, margin={"r": 0, "t": 35, "l": 0, "b": 0}, width=800, height=400, ) fig.show() # px.line_map() us_cities = pd.read_csv( "https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv" ) us_cities = us_cities.query("State in ['New York', 'Ohio']") fig = px.line_map(us_cities, lat="lat", lon="lon", color="State") fig.update_layout( title_text="px.line_map()", title_font_size=18, margin={"r": 0, "t": 35, "l": 0, "b": 0}, width=800, height=400, ) fig.show() # px.density_map() df = pd.read_csv( "https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv" ) df = df[:10] fig = px.density_map( df, lat="Latitude", lon="Longitude", z="Magnitude", radius=10, map_style="open-street-map", ) fig.update_layout( title_text="px.density_map()", title_font_size=18, margin={"r": 0, "t": 35, "l": 0, "b": 0}, width=800, height=400, ) fig.show() # px.choropleth_map() with urlopen( "https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json" ) as response: counties = json.load(response) df = pd.read_csv( "https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv", dtype={"fips": str}, ) fig = px.choropleth_map( df, geojson=counties, locations="fips", color="unemp", color_continuous_scale="Viridis", range_color=(0, 12), map_style="carto-positron", opacity=0.5, labels={"unemp": "unemployment rate"}, ) fig.update_layout( title_text="px.choropleth_map()", title_font_size=18, margin={"r": 0, "t": 35, "l": 0, "b": 0}, width=800, height=400, ) fig.show()
px.scatter_map() Percy test so that any changes in scattermap fitting behavior will be capturedpx.line_map() and px.density_map() already don't pass explicit center or zoomTo test locally: Run the code snippet above
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…() functions (now handled in plotly.js). Note: choropleth map auto-centering is not yet supported in plotly.js, but the default plotly.js zoom of 1 is still better than an arbitrary zoom of 8.
…test auto-fit behavior
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Could you update the zoom docstring in plotly/express/_doc.py? It still says the default is 8.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Good catch, will do. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
57a7e55 to
79d791a
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.