Matplotlib
¶import numpy as np
import geopandas as gp
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).
def dump_plot(plot, display=None):
import json
try:
import clipboard
except:
clipboard = None
from lets_plot._type_utils import standardize_dict
plot_dict = standardize_dict(plot.as_dict())
plot_json = json.dumps(plot_dict, indent=2)
if clipboard:
clipboard.copy('')
clipboard.copy(str(plot_json))
else:
if display is None:
display = True
if display:
print(plot_json)
return plot
LetsPlot.setup_html()
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[0,0], [0, 20], [5, 5], [0, 0], [5, 5], [20, 0], [0, 0]
]
],
[
[
[10, 10],[10, 20],[20, 20], [20, 10]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >
d = gp.read_file("""
{"type":"MultiLineString","coordinates":
[
[
[0,0], [0,0], [0, 5], [5, 5], [5, 0], [0, 0]
]
,
[
[10, 10],[10, 20],[20, 20],[20, 10], [10,10]
]
]
}""")
d.plot()
<Axes: >
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[10,5], [0, 10], [5, 5], [5, 0], [0, 5], [0, 5], [0, 0]
]
],
[
[
[10, 10],[10, 20],[20, 20], [20, 10]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[0, 0], [0, 20], [0, 20], [5, 5], [20, 0], [0, 0], [5, 5], [0, 3], [0, 0]
]
],
[
[
[10, 10],[10, 20],[20, 20],[20, 10], [10, 10]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[0, 0], [0, 0], [0, 0], [0, 20], [0, 20], [5, 5], [20, 0], [0, 0], [0, 0], [0, 0], [5, 5], [0, 3], [0, 0]
]
],
[
[
[10, 10],[10, 20],[20, 20],[20, 20],[20, 20],[20, 20],[20, 10], [10, 10], [10, 10], [10, 10], [10, 10]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[0,0], [0, 20], [5, 5], [5, 5], [20, 0], [0, 0]
]
],
[
[
[10, 10],[10, 20],[20, 20],[20, 10], [10,15]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >
d = gp.read_file("""
{"type":"MultiPolygon","coordinates":
[
[
[
[0,0], [0, 20], [5, 5], [20, 0], [0, 20], [0, 0], [5, 5]
]
],
[
[
[10, 10],[10, 20],[20, 20],[20, 10]
]
]
]
}""")
dump_plot(ggplot() + geom_polygon(map=d, color='black', size=1) + coord_fixed())
d.plot(edgecolor="black")
<Axes: >