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,300 @@
|
|
|
1
|
+
# Copyright (c) 2024. JetBrains s.r.o.
|
|
2
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
from .scale import _is_color_scale
|
|
10
|
+
from .scale import scale_gradientn
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import matplotlib
|
|
14
|
+
except ImportError:
|
|
15
|
+
matplotlib = None
|
|
16
|
+
|
|
17
|
+
__all__ = ['scale_cmapmpl',
|
|
18
|
+
'scale_fill_cmapmpl',
|
|
19
|
+
'scale_color_cmapmpl'
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _cmapmpl_to_hex(cmap) -> List[str]:
|
|
24
|
+
"""
|
|
25
|
+
Convert matplotlib colormap to list of hex colors.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
cmap: str or matplotlib colormap object
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
List of hex color strings.
|
|
34
|
+
"""
|
|
35
|
+
if matplotlib is None:
|
|
36
|
+
raise ImportError('matplotlib is not available. Please install it first.')
|
|
37
|
+
|
|
38
|
+
if isinstance(cmap, str):
|
|
39
|
+
cmap = matplotlib.colormaps[cmap]
|
|
40
|
+
if cmap is None:
|
|
41
|
+
raise ValueError(f"Unknown colormap: '{cmap}'")
|
|
42
|
+
|
|
43
|
+
if isinstance(cmap, matplotlib.colors.ListedColormap):
|
|
44
|
+
# colors from a discrete colormap (like "Dark2")
|
|
45
|
+
colors = cmap.colors
|
|
46
|
+
else:
|
|
47
|
+
# colors from a continuous colormap (like "plasma")
|
|
48
|
+
n = 256
|
|
49
|
+
values = [i / (n - 1) for i in range(n)]
|
|
50
|
+
colors = [cmap(value) for value in values]
|
|
51
|
+
|
|
52
|
+
return [matplotlib.colors.to_hex(c) for c in colors]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def scale_cmapmpl(aesthetic, *,
|
|
56
|
+
cmap,
|
|
57
|
+
name=None, breaks=None, labels=None, lablim=None,
|
|
58
|
+
limits=None, na_value=None, guide=None, trans=None, format=None):
|
|
59
|
+
"""
|
|
60
|
+
Create a scale for color-related aesthetic using matplotlib colormap.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
aesthetic : str or list
|
|
65
|
+
The name(s) of the aesthetic(s) that this scale works with.
|
|
66
|
+
Valid values are: 'color', 'fill', 'paint_a', 'paint_b', 'paint_c'.
|
|
67
|
+
cmap : str or matplotlib colormap object
|
|
68
|
+
The name of colormap or the colormap object to use.
|
|
69
|
+
name : str
|
|
70
|
+
The name of the scale - used as the axis label or the legend title.
|
|
71
|
+
If None, the default, the name of the scale
|
|
72
|
+
is taken from the first mapping used for that aesthetic.
|
|
73
|
+
breaks : list or dict
|
|
74
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
75
|
+
labels : list of str or dict
|
|
76
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
77
|
+
lablim : int, default=None
|
|
78
|
+
The maximum label length (in characters) before trimming is applied.
|
|
79
|
+
limits : list
|
|
80
|
+
A numeric vector of length two providing limits of the scale.
|
|
81
|
+
na_value
|
|
82
|
+
Missing values will be replaced with this value.
|
|
83
|
+
guide
|
|
84
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
85
|
+
or a call to a guide function (`guide_colorbar() <https://lets-plot.org/python/pages/api/lets_plot.guide_colorbar.html>`__,
|
|
86
|
+
`guide_legend() <https://lets-plot.org/python/pages/api/lets_plot.guide_legend.html>`__)
|
|
87
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
88
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
89
|
+
Name of built-in transformation.
|
|
90
|
+
format : str
|
|
91
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
92
|
+
|
|
93
|
+
- '.2f' -> '12.45'
|
|
94
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
95
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
96
|
+
|
|
97
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
``FeatureSpec``
|
|
102
|
+
The scale specification.
|
|
103
|
+
|
|
104
|
+
Notes
|
|
105
|
+
-----
|
|
106
|
+
This function requires matplotlib to be installed.
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
|
|
111
|
+
.. jupyter-execute::
|
|
112
|
+
:linenos:
|
|
113
|
+
:emphasize-lines: 6
|
|
114
|
+
|
|
115
|
+
from lets_plot import *
|
|
116
|
+
LetsPlot.setup_html()
|
|
117
|
+
x = list(range(50))
|
|
118
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
119
|
+
geom_tile(aes(color='x', fill='x')) + \\
|
|
120
|
+
scale_cmapmpl(aesthetic=['color', 'fill'], cmap='plasma', breaks=[5, 25, 45]) + \\
|
|
121
|
+
coord_cartesian() + \\
|
|
122
|
+
ggsize(600, 200)
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
if not _is_color_scale(aesthetic):
|
|
126
|
+
raise ValueError(
|
|
127
|
+
f"Invalid aesthetic: {aesthetic}. Expected one of: 'color', 'fill', 'paint_a', 'paint_b', 'paint_c'")
|
|
128
|
+
|
|
129
|
+
return scale_gradientn(aesthetic,
|
|
130
|
+
colors=_cmapmpl_to_hex(cmap),
|
|
131
|
+
name=name,
|
|
132
|
+
breaks=breaks,
|
|
133
|
+
labels=labels,
|
|
134
|
+
lablim=lablim,
|
|
135
|
+
limits=limits,
|
|
136
|
+
na_value=na_value,
|
|
137
|
+
guide=guide,
|
|
138
|
+
trans=trans,
|
|
139
|
+
format=format
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def scale_fill_cmapmpl(cmap, *,
|
|
144
|
+
name=None, breaks=None, labels=None, lablim=None,
|
|
145
|
+
limits=None, na_value=None, guide=None, trans=None, format=None):
|
|
146
|
+
"""
|
|
147
|
+
Create a scale for the 'fill' aesthetic using matplotlib colormap.
|
|
148
|
+
|
|
149
|
+
Parameters
|
|
150
|
+
----------
|
|
151
|
+
cmap : str or matplotlib colormap object
|
|
152
|
+
The name of colormap or the colormap object to use.
|
|
153
|
+
name : str
|
|
154
|
+
The name of the scale - used as the axis label or the legend title.
|
|
155
|
+
If None, the default, the name of the scale
|
|
156
|
+
is taken from the first mapping used for that aesthetic.
|
|
157
|
+
breaks : list or dict
|
|
158
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
159
|
+
labels : list of str or dict
|
|
160
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
161
|
+
lablim : int, default=None
|
|
162
|
+
The maximum label length (in characters) before trimming is applied.
|
|
163
|
+
limits : list
|
|
164
|
+
A numeric vector of length two providing limits of the scale.
|
|
165
|
+
na_value
|
|
166
|
+
Missing values will be replaced with this value.
|
|
167
|
+
guide
|
|
168
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
169
|
+
or a call to a guide function (`guide_colorbar() <https://lets-plot.org/python/pages/api/lets_plot.guide_colorbar.html>`__,
|
|
170
|
+
`guide_legend() <https://lets-plot.org/python/pages/api/lets_plot.guide_legend.html>`__)
|
|
171
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
172
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
173
|
+
Name of built-in transformation.
|
|
174
|
+
format : str
|
|
175
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
176
|
+
|
|
177
|
+
- '.2f' -> '12.45'
|
|
178
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
179
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
180
|
+
|
|
181
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
182
|
+
|
|
183
|
+
Returns
|
|
184
|
+
-------
|
|
185
|
+
``FeatureSpec``
|
|
186
|
+
The scale specification.
|
|
187
|
+
|
|
188
|
+
Notes
|
|
189
|
+
-----
|
|
190
|
+
This function requires matplotlib to be installed.
|
|
191
|
+
|
|
192
|
+
Examples
|
|
193
|
+
--------
|
|
194
|
+
|
|
195
|
+
.. jupyter-execute::
|
|
196
|
+
:linenos:
|
|
197
|
+
:emphasize-lines: 6
|
|
198
|
+
|
|
199
|
+
from lets_plot import *
|
|
200
|
+
LetsPlot.setup_html()
|
|
201
|
+
x = list(range(50))
|
|
202
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
203
|
+
geom_tile(aes(fill='x')) + \\
|
|
204
|
+
scale_fill_cmapmpl('plasma', breaks=[5, 25, 45]) + \\
|
|
205
|
+
coord_cartesian() + \\
|
|
206
|
+
ggsize(600, 200)
|
|
207
|
+
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
return scale_cmapmpl('fill',
|
|
211
|
+
cmap=cmap,
|
|
212
|
+
name=name,
|
|
213
|
+
breaks=breaks,
|
|
214
|
+
labels=labels,
|
|
215
|
+
lablim=lablim,
|
|
216
|
+
limits=limits,
|
|
217
|
+
na_value=na_value,
|
|
218
|
+
guide=guide,
|
|
219
|
+
trans=trans,
|
|
220
|
+
format=format)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def scale_color_cmapmpl(cmap, *,
|
|
224
|
+
name=None, breaks=None, labels=None, lablim=None, limits=None,
|
|
225
|
+
na_value=None, guide=None, trans=None, format=None):
|
|
226
|
+
"""
|
|
227
|
+
Create a scale for the 'color' aesthetic using matplotlib colormap.
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
cmap : str or matplotlib colormap object
|
|
232
|
+
The name of colormap or the colormap object to use.
|
|
233
|
+
name : str
|
|
234
|
+
The name of the scale - used as the axis label or the legend title.
|
|
235
|
+
If None, the default, the name of the scale
|
|
236
|
+
is taken from the first mapping used for that aesthetic.
|
|
237
|
+
breaks : list or dict
|
|
238
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
239
|
+
labels : list of str or dict
|
|
240
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
241
|
+
lablim : int, default=None
|
|
242
|
+
The maximum label length (in characters) before trimming is applied.
|
|
243
|
+
limits : list
|
|
244
|
+
A numeric vector of length two providing limits of the scale.
|
|
245
|
+
na_value
|
|
246
|
+
Missing values will be replaced with this value.
|
|
247
|
+
guide
|
|
248
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
249
|
+
or a call to a guide function (`guide_colorbar() <https://lets-plot.org/python/pages/api/lets_plot.guide_colorbar.html>`__,
|
|
250
|
+
`guide_legend() <https://lets-plot.org/python/pages/api/lets_plot.guide_legend.html>`__)
|
|
251
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
252
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
253
|
+
Name of built-in transformation.
|
|
254
|
+
format : str
|
|
255
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
256
|
+
|
|
257
|
+
- '.2f' -> '12.45'
|
|
258
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
259
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
260
|
+
|
|
261
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
262
|
+
|
|
263
|
+
Returns
|
|
264
|
+
-------
|
|
265
|
+
``FeatureSpec``
|
|
266
|
+
The scale specification.
|
|
267
|
+
|
|
268
|
+
Notes
|
|
269
|
+
-----
|
|
270
|
+
This function requires matplotlib to be installed.
|
|
271
|
+
|
|
272
|
+
Examples
|
|
273
|
+
--------
|
|
274
|
+
|
|
275
|
+
.. jupyter-execute::
|
|
276
|
+
:linenos:
|
|
277
|
+
:emphasize-lines: 6
|
|
278
|
+
|
|
279
|
+
from lets_plot import *
|
|
280
|
+
LetsPlot.setup_html()
|
|
281
|
+
x = list(range(50))
|
|
282
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
283
|
+
geom_tile(aes(color='x'), size=2) + \\
|
|
284
|
+
scale_color_cmapmpl('plasma', breaks=[5, 25, 45]) + \\
|
|
285
|
+
coord_cartesian() + \\
|
|
286
|
+
ggsize(600, 200)
|
|
287
|
+
|
|
288
|
+
"""
|
|
289
|
+
|
|
290
|
+
return scale_cmapmpl('color',
|
|
291
|
+
cmap=cmap,
|
|
292
|
+
name=name,
|
|
293
|
+
breaks=breaks,
|
|
294
|
+
labels=labels,
|
|
295
|
+
lablim=lablim,
|
|
296
|
+
limits=limits,
|
|
297
|
+
na_value=na_value,
|
|
298
|
+
guide=guide,
|
|
299
|
+
trans=trans,
|
|
300
|
+
format=format)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2019. JetBrains s.r.o.
|
|
3
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
4
|
+
#
|
|
5
|
+
from .core import DummySpec
|
|
6
|
+
from .scale_position import scale_x_continuous, scale_y_continuous, scale_x_discrete, scale_y_discrete
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Scale convenience functions to set the axis limits
|
|
10
|
+
#
|
|
11
|
+
__all__ = ['lims', 'xlim', 'ylim']
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def lims(x, y):
|
|
15
|
+
"""
|
|
16
|
+
This is a shortcut for supplying the ``limits`` parameter to the x and y axes.
|
|
17
|
+
Observations outside the range will be dropped.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
x : list of float
|
|
22
|
+
Limits (2 elements) for the x axis.
|
|
23
|
+
1st element defines lower limit, 2nd element defines upper limit.
|
|
24
|
+
None value in list means no bounds.
|
|
25
|
+
y : list of float
|
|
26
|
+
Limits (2 elements) for the y axis.
|
|
27
|
+
1st element defines lower limit, 2nd element defines upper limit.
|
|
28
|
+
None value in list means no bounds.
|
|
29
|
+
|
|
30
|
+
Returns
|
|
31
|
+
-------
|
|
32
|
+
``FeatureSpec``
|
|
33
|
+
Scale specification.
|
|
34
|
+
|
|
35
|
+
Examples
|
|
36
|
+
--------
|
|
37
|
+
.. jupyter-execute::
|
|
38
|
+
:linenos:
|
|
39
|
+
:emphasize-lines: 9
|
|
40
|
+
|
|
41
|
+
import numpy as np
|
|
42
|
+
from lets_plot import *
|
|
43
|
+
LetsPlot.setup_html()
|
|
44
|
+
n = 1000
|
|
45
|
+
np.random.seed(42)
|
|
46
|
+
x = np.random.normal(size=n)
|
|
47
|
+
y = np.random.normal(size=n)
|
|
48
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
49
|
+
geom_point() + lims([-2, 2], [-2, 2])
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
if x is None:
|
|
53
|
+
x = []
|
|
54
|
+
if y is None:
|
|
55
|
+
y = []
|
|
56
|
+
return xlim(*list(x)) + ylim(*list(y))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def xlim(*limits):
|
|
60
|
+
"""
|
|
61
|
+
This is a shortcut for supplying the ``limits`` parameter to the x axis.
|
|
62
|
+
Observations outside the range will be dropped.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
limits
|
|
67
|
+
Limits (2 parameters) for the x axis.
|
|
68
|
+
1st parameter defines lower limit, 2nd parameter defines upper limit.
|
|
69
|
+
None value means no bounds.
|
|
70
|
+
|
|
71
|
+
Returns
|
|
72
|
+
-------
|
|
73
|
+
``FeatureSpec``
|
|
74
|
+
Scale specification.
|
|
75
|
+
|
|
76
|
+
Examples
|
|
77
|
+
--------
|
|
78
|
+
.. jupyter-execute::
|
|
79
|
+
:linenos:
|
|
80
|
+
:emphasize-lines: 9
|
|
81
|
+
|
|
82
|
+
import numpy as np
|
|
83
|
+
from lets_plot import *
|
|
84
|
+
LetsPlot.setup_html()
|
|
85
|
+
n = 1000
|
|
86
|
+
np.random.seed(42)
|
|
87
|
+
x = np.random.normal(size=n)
|
|
88
|
+
y = np.random.normal(size=n)
|
|
89
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
90
|
+
geom_point() + xlim(-1, 1)
|
|
91
|
+
|
|
92
|
+
"""
|
|
93
|
+
return _limits("x", *limits)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def ylim(*limits):
|
|
97
|
+
"""
|
|
98
|
+
This is a shortcut for supplying the ``limits`` parameter to the y axis.
|
|
99
|
+
Observations outside the range will be dropped.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
limits
|
|
104
|
+
Limits (2 parameters) for the y axis.
|
|
105
|
+
1st parameter defines lower limit, 2nd parameter defines upper limit.
|
|
106
|
+
None value means no bounds.
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
``FeatureSpec``
|
|
111
|
+
Scale specification.
|
|
112
|
+
|
|
113
|
+
Examples
|
|
114
|
+
--------
|
|
115
|
+
.. jupyter-execute::
|
|
116
|
+
:linenos:
|
|
117
|
+
:emphasize-lines: 9
|
|
118
|
+
|
|
119
|
+
import numpy as np
|
|
120
|
+
from lets_plot import *
|
|
121
|
+
LetsPlot.setup_html()
|
|
122
|
+
n = 1000
|
|
123
|
+
np.random.seed(42)
|
|
124
|
+
x = np.random.normal(size=n)
|
|
125
|
+
y = np.random.normal(size=n)
|
|
126
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
127
|
+
geom_point() + ylim(-1, 1)
|
|
128
|
+
|
|
129
|
+
"""
|
|
130
|
+
return _limits("y", *limits)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _limits(aesthetic, *args):
|
|
134
|
+
if len(args) == 0:
|
|
135
|
+
return DummySpec()
|
|
136
|
+
elif any(isinstance(v, (str, bytes)) for v in args):
|
|
137
|
+
return _discrete_scale_limits(aesthetic=aesthetic, limits=list(args))
|
|
138
|
+
else:
|
|
139
|
+
return _continuous_scale_limits(aesthetic=aesthetic, limits=list(args))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _discrete_scale_limits(aesthetic, limits):
|
|
143
|
+
if aesthetic == "x":
|
|
144
|
+
return scale_x_discrete(limits=limits)
|
|
145
|
+
elif aesthetic == "y":
|
|
146
|
+
return scale_y_discrete(limits=limits)
|
|
147
|
+
raise ValueError("Unexpected aesthetic value '{}'".format(aesthetic))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _continuous_scale_limits(aesthetic, limits):
|
|
151
|
+
if aesthetic == "x":
|
|
152
|
+
return scale_x_continuous(limits=limits)
|
|
153
|
+
elif aesthetic == "y":
|
|
154
|
+
return scale_y_continuous(limits=limits)
|
|
155
|
+
raise ValueError("Unexpected aesthetic value '{}'".format(aesthetic))
|