Keeping line segments straight: flat parameter#
The flat parameter controls how line segments are handled by a non-Cartesian coordinate system or map projection.
flat=False(the default) allows the coordinate system or projection to transform the line, so it may appear curved.flat=Truekeeps line segments straight in plot/projected coordinates.
On Mercator/livemap this means a straight projected line, not a geodesic shortest path (see also an example). flat is not livemap-only; it is also useful with non-Cartesian coordinate systems such as coord_polar().
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()
Map coordinates#
route = {
'lon': [-156.78861, -99.12766],
'lat': [71.29056, 19.42847],
}
countries = geocode_countries(names=["US", "Canada", "Mexico"]).inc_res().get_boundaries()
gggrid([
(ggplot()
+ geom_map(data=countries, size=.25)
+ geom_path(aes(x="lon", y="lat"),
data=route, color="white", size=1,
manual_key=layer_key("default"))
+ geom_path(aes(x="lon", y="lat"),
data=route, color="coral", size=1, flat=True,
manual_key=layer_key("flat=True"))
+ coord_map(xlim=[-180, -50], ylim=[15, 75])
+ theme_void() + theme(legend_position='bottom') + flavor_darcula()
+ ggtitle("coord_map()")),
(ggplot()
+ geom_livemap(tiles=maptiles_lets_plot(theme='dark'))
+ geom_path(aes(x="lon", y="lat"),
data=route, color="white", size=1,
manual_key=layer_key("default"))
+ geom_path(aes(x="lon", y="lat"),
data=route, color="coral", size=1, flat=True,
manual_key=layer_key("flat=True"))
+ theme(legend_position='bottom') + flavor_darcula()
+ ggtitle("geom_livemap()"))
])
Polar coordinates#
data = {
"x": [0, 1, 1, 0, 0],
"y": [1, 1, 3, 3, 1],
}
(ggplot(data, aes("x", "y"))
+ geom_path(color="white", size=2,
manual_key=layer_key("default"))
+ geom_path(color="coral", size=1, flat=True,
manual_key=layer_key("flat=True"))
+ coord_polar(xlim=[0, 4], ylim=[0, 4])
+ theme_minimal2() + theme(legend_position='bottom', axis='blank') + flavor_darcula()
+ ggtitle("coord_polar()")
+ ggsize(500, 500))