lets-plot 4.8.1rc1__cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lets_plot/__init__.py +382 -0
- lets_plot/_global_settings.py +192 -0
- lets_plot/_kbridge.py +197 -0
- lets_plot/_type_utils.py +133 -0
- lets_plot/_version.py +6 -0
- lets_plot/bistro/__init__.py +16 -0
- lets_plot/bistro/_plot2d_common.py +106 -0
- lets_plot/bistro/corr.py +448 -0
- lets_plot/bistro/im.py +196 -0
- lets_plot/bistro/joint.py +192 -0
- lets_plot/bistro/qq.py +207 -0
- lets_plot/bistro/residual.py +341 -0
- lets_plot/bistro/waterfall.py +332 -0
- lets_plot/export/__init__.py +6 -0
- lets_plot/export/ggsave_.py +172 -0
- lets_plot/frontend_context/__init__.py +8 -0
- lets_plot/frontend_context/_configuration.py +140 -0
- lets_plot/frontend_context/_dynamic_configure_html.py +115 -0
- lets_plot/frontend_context/_frontend_ctx.py +16 -0
- lets_plot/frontend_context/_html_contexts.py +223 -0
- lets_plot/frontend_context/_intellij_python_json_ctx.py +38 -0
- lets_plot/frontend_context/_isolated_webview_panel_ctx.py +81 -0
- lets_plot/frontend_context/_json_contexts.py +39 -0
- lets_plot/frontend_context/_jupyter_notebook_ctx.py +82 -0
- lets_plot/frontend_context/_mime_types.py +7 -0
- lets_plot/frontend_context/_static_html_page_ctx.py +76 -0
- lets_plot/frontend_context/_static_svg_ctx.py +26 -0
- lets_plot/frontend_context/_webbr_html_page_ctx.py +29 -0
- lets_plot/frontend_context/sandbox.py +5 -0
- lets_plot/geo_data/__init__.py +19 -0
- lets_plot/geo_data/core.py +335 -0
- lets_plot/geo_data/geocoder.py +988 -0
- lets_plot/geo_data/geocodes.py +512 -0
- lets_plot/geo_data/gis/__init__.py +0 -0
- lets_plot/geo_data/gis/fluent_dict.py +201 -0
- lets_plot/geo_data/gis/geocoding_service.py +42 -0
- lets_plot/geo_data/gis/geometry.py +91 -0
- lets_plot/geo_data/gis/json_request.py +232 -0
- lets_plot/geo_data/gis/json_response.py +308 -0
- lets_plot/geo_data/gis/request.py +492 -0
- lets_plot/geo_data/gis/response.py +247 -0
- lets_plot/geo_data/livemap_helper.py +65 -0
- lets_plot/geo_data/to_geo_data_frame.py +141 -0
- lets_plot/geo_data/type_assertion.py +34 -0
- lets_plot/geo_data_internals/__init__.py +4 -0
- lets_plot/geo_data_internals/constants.py +13 -0
- lets_plot/geo_data_internals/utils.py +33 -0
- lets_plot/mapping.py +115 -0
- lets_plot/package_data/lets-plot.min.js +3 -0
- lets_plot/plot/__init__.py +64 -0
- lets_plot/plot/_global_theme.py +14 -0
- lets_plot/plot/annotation.py +290 -0
- lets_plot/plot/coord.py +242 -0
- lets_plot/plot/core.py +1071 -0
- lets_plot/plot/expand_limits_.py +78 -0
- lets_plot/plot/facet.py +210 -0
- lets_plot/plot/font_features.py +71 -0
- lets_plot/plot/geom.py +9146 -0
- lets_plot/plot/geom_extras.py +53 -0
- lets_plot/plot/geom_function_.py +219 -0
- lets_plot/plot/geom_imshow_.py +393 -0
- lets_plot/plot/geom_livemap_.py +343 -0
- lets_plot/plot/ggbunch_.py +96 -0
- lets_plot/plot/gggrid_.py +139 -0
- lets_plot/plot/ggtb_.py +81 -0
- lets_plot/plot/guide.py +231 -0
- lets_plot/plot/label.py +187 -0
- lets_plot/plot/marginal_layer.py +181 -0
- lets_plot/plot/plot.py +245 -0
- lets_plot/plot/pos.py +344 -0
- lets_plot/plot/sampling.py +338 -0
- lets_plot/plot/sandbox_.py +26 -0
- lets_plot/plot/scale.py +3580 -0
- lets_plot/plot/scale_colormap_mpl.py +300 -0
- lets_plot/plot/scale_convenience.py +155 -0
- lets_plot/plot/scale_identity_.py +653 -0
- lets_plot/plot/scale_position.py +1342 -0
- lets_plot/plot/series_meta.py +209 -0
- lets_plot/plot/stat.py +585 -0
- lets_plot/plot/subplots.py +331 -0
- lets_plot/plot/subplots_util.py +24 -0
- lets_plot/plot/theme_.py +790 -0
- lets_plot/plot/theme_set.py +418 -0
- lets_plot/plot/tooltip.py +486 -0
- lets_plot/plot/util.py +267 -0
- lets_plot/settings_utils.py +244 -0
- lets_plot/tilesets.py +429 -0
- lets_plot-4.8.1rc1.dist-info/METADATA +221 -0
- lets_plot-4.8.1rc1.dist-info/RECORD +97 -0
- lets_plot-4.8.1rc1.dist-info/WHEEL +6 -0
- lets_plot-4.8.1rc1.dist-info/licenses/LICENSE +21 -0
- lets_plot-4.8.1rc1.dist-info/licenses/licenses/LICENSE.FreeType +166 -0
- lets_plot-4.8.1rc1.dist-info/licenses/licenses/LICENSE.ImageMagick +106 -0
- lets_plot-4.8.1rc1.dist-info/licenses/licenses/LICENSE.expat +21 -0
- lets_plot-4.8.1rc1.dist-info/licenses/licenses/LICENSE.fontconfig +200 -0
- lets_plot-4.8.1rc1.dist-info/top_level.txt +2 -0
- lets_plot_kotlin_bridge.cpython-311-x86_64-linux-gnu.so +0 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from .geocoder import Geocoder, ReverseGeocoder, NamesGeocoder
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'distance',
|
|
9
|
+
|
|
10
|
+
'geocode',
|
|
11
|
+
'geocode_cities',
|
|
12
|
+
'geocode_counties',
|
|
13
|
+
'geocode_states',
|
|
14
|
+
'geocode_countries',
|
|
15
|
+
'reverse_geocode'
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
UNITS_DICT = {
|
|
19
|
+
'mi': 3959,
|
|
20
|
+
'km': 6371
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
GEOFUNC_TYPES = {
|
|
24
|
+
'centroids': 'centroids',
|
|
25
|
+
'boundaries': 'boundaries',
|
|
26
|
+
'limits': 'limits',
|
|
27
|
+
'region': 'regions'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def geocode(level=None, names=None, countries=None, states=None, counties=None, scope=None) -> NamesGeocoder:
|
|
32
|
+
"""
|
|
33
|
+
Create a `NamesGeocoder <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html>`__.
|
|
34
|
+
Allow to refine ambiguous request with `where() <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html#lets_plot.geo_data.NamesGeocoder.where>`__ method,
|
|
35
|
+
scope that limits area of geocoding or with parents.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
level : {'country', 'state', 'county', 'city'}
|
|
40
|
+
The level of administrative division. Autodetection by default.
|
|
41
|
+
names : list or str
|
|
42
|
+
Names of objects to be geocoded.
|
|
43
|
+
For 'state' level: 'US-48' returns continental part of United States (48 states)
|
|
44
|
+
in a compact form.
|
|
45
|
+
countries : list
|
|
46
|
+
Parent countries. Should have same size as names. Can contain strings or ``Geocoder`` objects.
|
|
47
|
+
states : list
|
|
48
|
+
Parent states. Should have same size as names. Can contain strings or ``Geocoder`` objects.
|
|
49
|
+
counties : list
|
|
50
|
+
Parent counties. Should have same size as names. Can contain strings or ``Geocoder`` objects.
|
|
51
|
+
scope : str or ``Geocoder``
|
|
52
|
+
Limits area of geocoding. If parent country is set then error will be generated.
|
|
53
|
+
If type is a string - geoobject should have geocoded scope in parents.
|
|
54
|
+
If type is a ``Geocoder`` - geoobject should have geocoded scope in parents.
|
|
55
|
+
Scope should contain only one entry.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
``NamesGeocoder``
|
|
60
|
+
Geocoder object specification.
|
|
61
|
+
|
|
62
|
+
Examples
|
|
63
|
+
--------
|
|
64
|
+
.. jupyter-execute::
|
|
65
|
+
:linenos:
|
|
66
|
+
:emphasize-lines: 5
|
|
67
|
+
|
|
68
|
+
from IPython.display import display
|
|
69
|
+
from lets_plot import *
|
|
70
|
+
from lets_plot.geo_data import *
|
|
71
|
+
LetsPlot.setup_html()
|
|
72
|
+
states = geocode('state').scope('Italy').get_boundaries(6)
|
|
73
|
+
display(states.head())
|
|
74
|
+
ggplot() + geom_map(data=states)
|
|
75
|
+
|
|
76
|
+
|
|
|
77
|
+
|
|
78
|
+
.. jupyter-execute::
|
|
79
|
+
:linenos:
|
|
80
|
+
:emphasize-lines: 5, 8
|
|
81
|
+
|
|
82
|
+
from IPython.display import display
|
|
83
|
+
from lets_plot import *
|
|
84
|
+
from lets_plot.geo_data import *
|
|
85
|
+
LetsPlot.setup_html()
|
|
86
|
+
states = geocode(level='state', scope='US').get_geocodes()
|
|
87
|
+
display(states.head())
|
|
88
|
+
names = ['York'] * len(states.state)
|
|
89
|
+
cities = geocode(names=names, states=states.state).ignore_not_found().get_centroids()
|
|
90
|
+
display(cities.head())
|
|
91
|
+
ggplot() + \\
|
|
92
|
+
geom_livemap() + \\
|
|
93
|
+
geom_point(data=cities, tooltips=layer_tooltips().line('@{found name}'))
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
return NamesGeocoder(level, names) \
|
|
97
|
+
.scope(scope) \
|
|
98
|
+
.countries(countries) \
|
|
99
|
+
.states(states) \
|
|
100
|
+
.counties(counties)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def geocode_cities(names=None) -> NamesGeocoder:
|
|
104
|
+
"""
|
|
105
|
+
Create a `NamesGeocoder <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html>`__ object for cities.
|
|
106
|
+
Allow to refine ambiguous request with `where() <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html#lets_plot.geo_data.NamesGeocoder.where>`__ method,
|
|
107
|
+
with a scope that limits area of geocoding or with parents.
|
|
108
|
+
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
names : str or list
|
|
112
|
+
Names of objects to be geocoded.
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
``NamesGeocoder``
|
|
117
|
+
Geocoder object specification.
|
|
118
|
+
|
|
119
|
+
Examples
|
|
120
|
+
--------
|
|
121
|
+
.. jupyter-execute::
|
|
122
|
+
:linenos:
|
|
123
|
+
:emphasize-lines: 5
|
|
124
|
+
|
|
125
|
+
from IPython.display import display
|
|
126
|
+
from lets_plot import *
|
|
127
|
+
from lets_plot.geo_data import *
|
|
128
|
+
LetsPlot.setup_html()
|
|
129
|
+
cities = geocode_cities(['York', 'Jersey'])\\
|
|
130
|
+
.where(name='Jersey', scope='New Jersey').get_boundaries()
|
|
131
|
+
display(cities)
|
|
132
|
+
ggplot() + geom_map(aes(fill='found name'), data=cities, color='white')
|
|
133
|
+
|
|
134
|
+
"""
|
|
135
|
+
return NamesGeocoder('city', names)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def geocode_counties(names=None) -> NamesGeocoder:
|
|
139
|
+
"""
|
|
140
|
+
Create a `NamesGeocoder <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html>`__ object for counties.
|
|
141
|
+
Allow to refine ambiguous request with `where() <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html#lets_plot.geo_data.NamesGeocoder.where>`__ method,
|
|
142
|
+
with a scope that limits area of geocoding or with parents.
|
|
143
|
+
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
names : str or list
|
|
147
|
+
Names of objects to be geocoded.
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
``NamesGeocoder``
|
|
152
|
+
Geocoder object specification.
|
|
153
|
+
|
|
154
|
+
Examples
|
|
155
|
+
--------
|
|
156
|
+
.. jupyter-execute::
|
|
157
|
+
:linenos:
|
|
158
|
+
:emphasize-lines: 5
|
|
159
|
+
|
|
160
|
+
from IPython.display import display
|
|
161
|
+
from lets_plot import *
|
|
162
|
+
from lets_plot.geo_data import *
|
|
163
|
+
LetsPlot.setup_html()
|
|
164
|
+
counties = geocode_counties().scope('NY').get_boundaries(9)
|
|
165
|
+
display(counties.head())
|
|
166
|
+
ggplot() + geom_map(data=counties) + ggtitle('New York State Counties')
|
|
167
|
+
|
|
168
|
+
"""
|
|
169
|
+
return NamesGeocoder('county', names)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def geocode_states(names=None) -> NamesGeocoder:
|
|
173
|
+
"""
|
|
174
|
+
Create a `NamesGeocoder <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html>`__ object for states.
|
|
175
|
+
Allow to refine ambiguous request with `where() <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html#lets_plot.geo_data.NamesGeocoder.where>`__ method,
|
|
176
|
+
with a scope that limits area of geocoding or with parents.
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
names : str or list
|
|
181
|
+
Names of objects to be geocoded.
|
|
182
|
+
|
|
183
|
+
Returns
|
|
184
|
+
-------
|
|
185
|
+
``NamesGeocoder``
|
|
186
|
+
Geocoder object specification.
|
|
187
|
+
|
|
188
|
+
Examples
|
|
189
|
+
--------
|
|
190
|
+
.. jupyter-execute::
|
|
191
|
+
:linenos:
|
|
192
|
+
:emphasize-lines: 5
|
|
193
|
+
|
|
194
|
+
from IPython.display import display
|
|
195
|
+
from lets_plot import *
|
|
196
|
+
from lets_plot.geo_data import *
|
|
197
|
+
LetsPlot.setup_html()
|
|
198
|
+
states = geocode_states().scope('UK').get_boundaries()
|
|
199
|
+
display(states)
|
|
200
|
+
ggplot() + \\
|
|
201
|
+
geom_map(aes(fill='found name'), data=states, color='white') + \\
|
|
202
|
+
ggtitle('UK States')
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
return NamesGeocoder('state', names)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def geocode_countries(names=None) -> NamesGeocoder:
|
|
209
|
+
"""
|
|
210
|
+
Create a `NamesGeocoder <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html>`__ object for countries.
|
|
211
|
+
Allow to refine ambiguous request with `where() <https://lets-plot.org/python/pages/api/lets_plot.geo_data.NamesGeocoder.html#lets_plot.geo_data.NamesGeocoder.where>`__ method.
|
|
212
|
+
|
|
213
|
+
Parameters
|
|
214
|
+
----------
|
|
215
|
+
names : str or list
|
|
216
|
+
Names of objects to be geocoded.
|
|
217
|
+
|
|
218
|
+
Returns
|
|
219
|
+
-------
|
|
220
|
+
``NamesGeocoder``
|
|
221
|
+
Geocoder object specification.
|
|
222
|
+
|
|
223
|
+
Examples
|
|
224
|
+
--------
|
|
225
|
+
.. jupyter-execute::
|
|
226
|
+
:linenos:
|
|
227
|
+
:emphasize-lines: 5
|
|
228
|
+
|
|
229
|
+
from IPython.display import display
|
|
230
|
+
from lets_plot import *
|
|
231
|
+
from lets_plot.geo_data import *
|
|
232
|
+
LetsPlot.setup_html()
|
|
233
|
+
countries = geocode_countries(['Germany', 'Poland']).inc_res().get_boundaries()
|
|
234
|
+
display(countries)
|
|
235
|
+
ggplot() + geom_map(aes(fill='found name'), data=countries, color='white')
|
|
236
|
+
|
|
237
|
+
"""
|
|
238
|
+
return NamesGeocoder('country', names)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def reverse_geocode(lon, lat, level=None, scope=None) -> ReverseGeocoder:
|
|
242
|
+
"""
|
|
243
|
+
Convert a location as described by geographic coordinates to a ``ReverseGeocoder`` object.
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
lon : float
|
|
248
|
+
Longitude coordinate of the geoobject.
|
|
249
|
+
lat : float
|
|
250
|
+
Latitude coordinate of the geoobject.
|
|
251
|
+
level : {'country', 'state', 'county', 'city'}
|
|
252
|
+
The level of administrative division.
|
|
253
|
+
scope : str or ``Geocoder``
|
|
254
|
+
Specify this for resolving conflicts for disputed territories.
|
|
255
|
+
|
|
256
|
+
Returns
|
|
257
|
+
-------
|
|
258
|
+
``ReverseGeocoder``
|
|
259
|
+
Geocoder object specification.
|
|
260
|
+
|
|
261
|
+
Examples
|
|
262
|
+
--------
|
|
263
|
+
.. jupyter-execute::
|
|
264
|
+
:linenos:
|
|
265
|
+
:emphasize-lines: 5
|
|
266
|
+
|
|
267
|
+
from IPython.display import display
|
|
268
|
+
from lets_plot import *
|
|
269
|
+
from lets_plot.geo_data import *
|
|
270
|
+
LetsPlot.setup_html()
|
|
271
|
+
city = reverse_geocode(-73.87, 40.68, level='city').get_boundaries()
|
|
272
|
+
display(city)
|
|
273
|
+
ggplot() + geom_map(data=city) + ggtitle(city.iloc[0]['found name'])
|
|
274
|
+
|
|
275
|
+
"""
|
|
276
|
+
return ReverseGeocoder(lon, lat, level, scope)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def distance(lon0, lat0, lon1, lat1, units='km'):
|
|
280
|
+
"""
|
|
281
|
+
Calculate the distance between two points. Return result in kilometers or miles.
|
|
282
|
+
|
|
283
|
+
Parameters
|
|
284
|
+
----------
|
|
285
|
+
lon0 : float
|
|
286
|
+
Longitude coordinate of the first point.
|
|
287
|
+
lat0 : float
|
|
288
|
+
Latitude coordinate of the first point.
|
|
289
|
+
lon1 : float
|
|
290
|
+
Longitude coordinate of the second point.
|
|
291
|
+
lat1 : float
|
|
292
|
+
Latitude coordinate of the second point.
|
|
293
|
+
units : {'mi', 'km'}, default='km'
|
|
294
|
+
The units in which the result will be obtained.
|
|
295
|
+
There are shorthands for values: 'mi' (miles), 'km' (kilometers).
|
|
296
|
+
|
|
297
|
+
Returns
|
|
298
|
+
-------
|
|
299
|
+
float
|
|
300
|
+
Distance between the points.
|
|
301
|
+
|
|
302
|
+
Examples
|
|
303
|
+
--------
|
|
304
|
+
.. jupyter-execute::
|
|
305
|
+
:linenos:
|
|
306
|
+
:emphasize-lines: 3
|
|
307
|
+
|
|
308
|
+
from lets_plot.geo_data import *
|
|
309
|
+
cities = geocode_cities(['New York', 'Chicago']).get_centroids().geometry
|
|
310
|
+
distance(cities[0].x, cities[0].y, cities[1].x, cities[1].y, units='mi')
|
|
311
|
+
|
|
312
|
+
"""
|
|
313
|
+
return _calc_distance(lon0, lat0, lon1, lat1, units)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _calc_distance(lon0, lat0, lon1, lat1, u):
|
|
317
|
+
r = _prepare_units(u)
|
|
318
|
+
|
|
319
|
+
lon0, lat0, lon1, lat1 = map(np.radians, [lon0, lat0, lon1, lat1])
|
|
320
|
+
|
|
321
|
+
dlon = lon1 - lon0
|
|
322
|
+
dlat = lat1 - lat0
|
|
323
|
+
|
|
324
|
+
a = np.sin(dlat / 2.0) ** 2 + np.cos(lat0) * np.cos(lat1) * np.sin(dlon / 2.0) ** 2
|
|
325
|
+
|
|
326
|
+
c = 2 * np.arcsin(np.sqrt(a))
|
|
327
|
+
return c * r
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _prepare_units(units: Any) -> float:
|
|
331
|
+
try:
|
|
332
|
+
return UNITS_DICT[units]
|
|
333
|
+
except KeyError:
|
|
334
|
+
raise ValueError('Wrong units: {}. The units can take the following values: '
|
|
335
|
+
'mi (miles), km (kilometers).'.format(units))
|