Download notebook (.ipynb)

Zooming#

import pandas as pd

from lets_plot import *
from lets_plot.geo_data import *
The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).
LetsPlot.setup_html()
df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/midwest.csv')
states = geocode('state', df.state.unique(), scope='US').get_boundaries(9)
states.head()
state found name geometry
0 IL Illinois MULTIPOLYGON (((-89.13301 36.98200, -89.16777 ...
1 IN Indiana MULTIPOLYGON (((-84.81993 39.10544, -84.83405 ...
2 MI Michigan MULTIPOLYGON (((-90.41862 46.56636, -90.00014 ...
3 OH Ohio MULTIPOLYGON (((-82.59342 38.42186, -82.60076 ...
4 WI Wisconsin MULTIPOLYGON (((-91.21771 43.50055, -91.21829 ...
p = ggplot() + geom_map(data=states, tooltips=layer_tooltips().line('@{found name}')) + theme_void()

Zooming without clipping#

Preferred type of zooming.

p1 = p + ggtitle("Default")
p2 = p + coord_map(ylim=[36, 43]) + ggtitle("Zoom with coord_map()")

gggrid([p1, p2]) + ggsize(1000, 375)

Zooming with clipping#

Removes unseen data points.

p3 = p + ggtitle("Default")
p4 = p + scale_x_continuous(limits=[-92, -82]) + ylim(36, 43) + ggtitle("Zoom with ylim()")

gggrid([p3, p4]) + ggsize(1000, 375)