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,1342 @@
|
|
|
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 .scale import _scale
|
|
6
|
+
from .util import as_boolean
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Position Scales
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
__all__ = ['scale_x_discrete', 'scale_y_discrete',
|
|
13
|
+
'scale_x_discrete_reversed', 'scale_y_discrete_reversed',
|
|
14
|
+
'scale_x_continuous', 'scale_y_continuous',
|
|
15
|
+
'scale_x_log10', 'scale_y_log10',
|
|
16
|
+
'scale_x_log2', 'scale_y_log2',
|
|
17
|
+
'scale_x_reverse', 'scale_y_reverse',
|
|
18
|
+
'scale_x_datetime', 'scale_y_datetime',
|
|
19
|
+
'scale_x_time', 'scale_y_time',
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Continuous Scales
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
def scale_x_continuous(name=None, *,
|
|
28
|
+
breaks=None, labels=None, lablim=None,
|
|
29
|
+
limits=None,
|
|
30
|
+
expand=None,
|
|
31
|
+
na_value=None,
|
|
32
|
+
trans=None,
|
|
33
|
+
format=None,
|
|
34
|
+
position=None
|
|
35
|
+
):
|
|
36
|
+
"""
|
|
37
|
+
Continuous position scale x.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
name : str
|
|
42
|
+
The name of the scale - used as the axis label or the legend title.
|
|
43
|
+
If None, the default, the name of the scale
|
|
44
|
+
is taken from the first mapping used for that aesthetic.
|
|
45
|
+
breaks : list or dict
|
|
46
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
47
|
+
labels : list of str or dict
|
|
48
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
49
|
+
lablim : int, default=None
|
|
50
|
+
The maximum label length (in characters) before trimming is applied.
|
|
51
|
+
limits : list
|
|
52
|
+
A numeric vector of length two providing limits of the scale.
|
|
53
|
+
expand : list
|
|
54
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
55
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
56
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
57
|
+
na_value
|
|
58
|
+
Missing values will be replaced with this value.
|
|
59
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
60
|
+
Name of built-in transformation.
|
|
61
|
+
format : str
|
|
62
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
63
|
+
|
|
64
|
+
- '.2f' -> '12.45'
|
|
65
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
66
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
67
|
+
|
|
68
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
69
|
+
position : str
|
|
70
|
+
The position of the axis:
|
|
71
|
+
|
|
72
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
73
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
``FeatureSpec``
|
|
78
|
+
Scale specification.
|
|
79
|
+
|
|
80
|
+
Examples
|
|
81
|
+
--------
|
|
82
|
+
.. jupyter-execute::
|
|
83
|
+
:linenos:
|
|
84
|
+
:emphasize-lines: 7-8
|
|
85
|
+
|
|
86
|
+
import numpy as np
|
|
87
|
+
from lets_plot import *
|
|
88
|
+
LetsPlot.setup_html()
|
|
89
|
+
np.random.seed(42)
|
|
90
|
+
x = np.random.randint(-10, 10, size=100)
|
|
91
|
+
ggplot({'x': x}, aes(x='x')) + geom_bar(stat='bin', bins=8) + \\
|
|
92
|
+
scale_x_continuous(name='observations', breaks=[-9, -3, 3, 9], \\
|
|
93
|
+
limits=[-8, 11], expand=[.2], format='.1f')
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
return _scale('x',
|
|
97
|
+
name=name,
|
|
98
|
+
breaks=breaks,
|
|
99
|
+
labels=labels,
|
|
100
|
+
lablim=lablim,
|
|
101
|
+
limits=limits,
|
|
102
|
+
expand=expand,
|
|
103
|
+
na_value=na_value,
|
|
104
|
+
trans=trans,
|
|
105
|
+
guide=None,
|
|
106
|
+
format=format,
|
|
107
|
+
position=position,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def scale_y_continuous(name=None, *,
|
|
112
|
+
breaks=None, labels=None, lablim=None,
|
|
113
|
+
limits=None,
|
|
114
|
+
expand=None,
|
|
115
|
+
na_value=None,
|
|
116
|
+
trans=None,
|
|
117
|
+
format=None,
|
|
118
|
+
position=None
|
|
119
|
+
):
|
|
120
|
+
"""
|
|
121
|
+
Continuous position scale y.
|
|
122
|
+
|
|
123
|
+
Parameters
|
|
124
|
+
----------
|
|
125
|
+
name : str
|
|
126
|
+
The name of the scale - used as the axis label or the legend title.
|
|
127
|
+
If None, the default, the name of the scale
|
|
128
|
+
is taken from the first mapping used for that aesthetic.
|
|
129
|
+
breaks : list or dict
|
|
130
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
131
|
+
labels : list of str or dict
|
|
132
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
133
|
+
lablim : int, default=None
|
|
134
|
+
The maximum label length (in characters) before trimming is applied.
|
|
135
|
+
limits : list
|
|
136
|
+
A numeric vector of length two providing limits of the scale.
|
|
137
|
+
expand : list
|
|
138
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
139
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
140
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
141
|
+
na_value
|
|
142
|
+
Missing values will be replaced with this value.
|
|
143
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
144
|
+
Name of built-in transformation.
|
|
145
|
+
format : str
|
|
146
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
147
|
+
|
|
148
|
+
- '.2f' -> '12.45'
|
|
149
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
150
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
151
|
+
|
|
152
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
153
|
+
position : str
|
|
154
|
+
The position of the axis:
|
|
155
|
+
|
|
156
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
157
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
158
|
+
|
|
159
|
+
Returns
|
|
160
|
+
-------
|
|
161
|
+
``FeatureSpec``
|
|
162
|
+
Scale specification.
|
|
163
|
+
|
|
164
|
+
Examples
|
|
165
|
+
--------
|
|
166
|
+
.. jupyter-execute::
|
|
167
|
+
:linenos:
|
|
168
|
+
:emphasize-lines: 7-8
|
|
169
|
+
|
|
170
|
+
import numpy as np
|
|
171
|
+
from lets_plot import *
|
|
172
|
+
LetsPlot.setup_html()
|
|
173
|
+
np.random.seed(42)
|
|
174
|
+
x = np.random.randint(-10, 10, size=1000)
|
|
175
|
+
ggplot({'x': x}, aes(x='x')) + geom_bar(stat='bin', bins=4) + \\
|
|
176
|
+
scale_y_continuous(name='hundreds', breaks=[100, 200, 300, 400], \\
|
|
177
|
+
labels=['one', 'two', 'three', 'four'])
|
|
178
|
+
|
|
179
|
+
"""
|
|
180
|
+
return _scale('y',
|
|
181
|
+
name=name,
|
|
182
|
+
breaks=breaks,
|
|
183
|
+
labels=labels,
|
|
184
|
+
lablim=lablim,
|
|
185
|
+
limits=limits,
|
|
186
|
+
expand=expand,
|
|
187
|
+
na_value=na_value,
|
|
188
|
+
trans=trans,
|
|
189
|
+
guide=None,
|
|
190
|
+
format=format,
|
|
191
|
+
position=position,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def scale_x_log10(name=None, *,
|
|
196
|
+
breaks=None, labels=None, lablim=None,
|
|
197
|
+
limits=None,
|
|
198
|
+
expand=None,
|
|
199
|
+
na_value=None,
|
|
200
|
+
format=None,
|
|
201
|
+
position=None
|
|
202
|
+
):
|
|
203
|
+
"""
|
|
204
|
+
Continuous position scale x where trans='log10'.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
name : str
|
|
209
|
+
The name of the scale - used as the axis label or the legend title.
|
|
210
|
+
If None, the default, the name of the scale
|
|
211
|
+
is taken from the first mapping used for that aesthetic.
|
|
212
|
+
breaks : list or dict
|
|
213
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
214
|
+
labels : list of str or dict
|
|
215
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
216
|
+
lablim : int, default=None
|
|
217
|
+
The maximum label length (in characters) before trimming is applied.
|
|
218
|
+
limits : list
|
|
219
|
+
A numeric vector of length two providing limits of the scale.
|
|
220
|
+
expand : list
|
|
221
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
222
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
223
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
224
|
+
na_value
|
|
225
|
+
Missing values will be replaced with this value.
|
|
226
|
+
format : str
|
|
227
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
228
|
+
|
|
229
|
+
- '.2f' -> '12.45'
|
|
230
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
231
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
232
|
+
|
|
233
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
234
|
+
position : str
|
|
235
|
+
The position of the axis:
|
|
236
|
+
|
|
237
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
238
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
239
|
+
|
|
240
|
+
Returns
|
|
241
|
+
-------
|
|
242
|
+
``FeatureSpec``
|
|
243
|
+
Scale specification.
|
|
244
|
+
|
|
245
|
+
Examples
|
|
246
|
+
--------
|
|
247
|
+
.. jupyter-execute::
|
|
248
|
+
:linenos:
|
|
249
|
+
:emphasize-lines: 6
|
|
250
|
+
|
|
251
|
+
import numpy as np
|
|
252
|
+
from lets_plot import *
|
|
253
|
+
LetsPlot.setup_html()
|
|
254
|
+
np.random.seed(42)
|
|
255
|
+
x = np.power(10, np.random.randint(9, size=100))
|
|
256
|
+
ggplot({'x': x}, aes(x='x')) + geom_bar() + scale_x_log10()
|
|
257
|
+
|
|
258
|
+
"""
|
|
259
|
+
return scale_x_continuous(name,
|
|
260
|
+
breaks=breaks,
|
|
261
|
+
labels=labels,
|
|
262
|
+
lablim=lablim,
|
|
263
|
+
limits=limits,
|
|
264
|
+
expand=expand,
|
|
265
|
+
na_value=na_value,
|
|
266
|
+
trans='log10',
|
|
267
|
+
format=format,
|
|
268
|
+
position=position,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def scale_y_log10(name=None, *,
|
|
273
|
+
breaks=None, labels=None, lablim=None,
|
|
274
|
+
limits=None,
|
|
275
|
+
expand=None,
|
|
276
|
+
na_value=None,
|
|
277
|
+
format=None,
|
|
278
|
+
position=None
|
|
279
|
+
):
|
|
280
|
+
"""
|
|
281
|
+
Continuous position scales y where trans='log10'.
|
|
282
|
+
|
|
283
|
+
Parameters
|
|
284
|
+
----------
|
|
285
|
+
name : str
|
|
286
|
+
The name of the scale - used as the axis label or the legend title.
|
|
287
|
+
If None, the default, the name of the scale
|
|
288
|
+
is taken from the first mapping used for that aesthetic.
|
|
289
|
+
breaks : list or dict
|
|
290
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
291
|
+
labels : list of str or dict
|
|
292
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
293
|
+
lablim : int, default=None
|
|
294
|
+
The maximum label length (in characters) before trimming is applied.
|
|
295
|
+
limits : list
|
|
296
|
+
A numeric vector of length two providing limits of the scale.
|
|
297
|
+
expand : list
|
|
298
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
299
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
300
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
301
|
+
na_value
|
|
302
|
+
Missing values will be replaced with this value.
|
|
303
|
+
format : str
|
|
304
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
305
|
+
|
|
306
|
+
- '.2f' -> '12.45'
|
|
307
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
308
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
309
|
+
|
|
310
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
311
|
+
position : str
|
|
312
|
+
The position of the axis:
|
|
313
|
+
|
|
314
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
315
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
316
|
+
|
|
317
|
+
Returns
|
|
318
|
+
-------
|
|
319
|
+
``FeatureSpec``
|
|
320
|
+
Scale specification.
|
|
321
|
+
|
|
322
|
+
Examples
|
|
323
|
+
--------
|
|
324
|
+
.. jupyter-execute::
|
|
325
|
+
:linenos:
|
|
326
|
+
:emphasize-lines: 6
|
|
327
|
+
|
|
328
|
+
import numpy as np
|
|
329
|
+
from lets_plot import *
|
|
330
|
+
LetsPlot.setup_html()
|
|
331
|
+
np.random.seed(42)
|
|
332
|
+
x = np.random.poisson(size=100)
|
|
333
|
+
ggplot({'x': x}, aes(x='x')) + geom_histogram() + scale_y_log10()
|
|
334
|
+
|
|
335
|
+
"""
|
|
336
|
+
return scale_y_continuous(name,
|
|
337
|
+
breaks=breaks,
|
|
338
|
+
labels=labels,
|
|
339
|
+
lablim=lablim,
|
|
340
|
+
limits=limits,
|
|
341
|
+
expand=expand,
|
|
342
|
+
na_value=na_value,
|
|
343
|
+
trans='log10',
|
|
344
|
+
format=format,
|
|
345
|
+
position=position,
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def scale_x_log2(name=None, *,
|
|
350
|
+
breaks=None, labels=None, lablim=None,
|
|
351
|
+
limits=None,
|
|
352
|
+
expand=None,
|
|
353
|
+
na_value=None,
|
|
354
|
+
format=None,
|
|
355
|
+
position=None
|
|
356
|
+
):
|
|
357
|
+
"""
|
|
358
|
+
Continuous position scale x where trans='log2'.
|
|
359
|
+
|
|
360
|
+
Parameters
|
|
361
|
+
----------
|
|
362
|
+
name : str
|
|
363
|
+
The name of the scale - used as the axis label or the legend title.
|
|
364
|
+
If None, the default, the name of the scale
|
|
365
|
+
is taken from the first mapping used for that aesthetic.
|
|
366
|
+
breaks : list or dict
|
|
367
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
368
|
+
labels : list of str or dict
|
|
369
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
370
|
+
lablim : int, default=None
|
|
371
|
+
The maximum label length (in characters) before trimming is applied.
|
|
372
|
+
limits : list
|
|
373
|
+
A numeric vector of length two providing limits of the scale.
|
|
374
|
+
expand : list
|
|
375
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
376
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
377
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
378
|
+
na_value
|
|
379
|
+
Missing values will be replaced with this value.
|
|
380
|
+
format : str
|
|
381
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
382
|
+
|
|
383
|
+
- '.2f' -> '12.45'
|
|
384
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
385
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
386
|
+
|
|
387
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
388
|
+
position : str
|
|
389
|
+
The position of the axis:
|
|
390
|
+
|
|
391
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
392
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
393
|
+
|
|
394
|
+
Returns
|
|
395
|
+
-------
|
|
396
|
+
``FeatureSpec``
|
|
397
|
+
Scale specification.
|
|
398
|
+
|
|
399
|
+
Examples
|
|
400
|
+
--------
|
|
401
|
+
.. jupyter-execute::
|
|
402
|
+
:linenos:
|
|
403
|
+
:emphasize-lines: 6
|
|
404
|
+
|
|
405
|
+
import numpy as np
|
|
406
|
+
from lets_plot import *
|
|
407
|
+
LetsPlot.setup_html()
|
|
408
|
+
np.random.seed(42)
|
|
409
|
+
x = np.power(2, np.random.randint(9, size=100))
|
|
410
|
+
ggplot({'x': x}, aes(x='x')) + geom_bar() + scale_x_log2()
|
|
411
|
+
|
|
412
|
+
"""
|
|
413
|
+
return scale_x_continuous(name,
|
|
414
|
+
breaks=breaks,
|
|
415
|
+
labels=labels,
|
|
416
|
+
lablim=lablim,
|
|
417
|
+
limits=limits,
|
|
418
|
+
expand=expand,
|
|
419
|
+
na_value=na_value,
|
|
420
|
+
trans='log2',
|
|
421
|
+
format=format,
|
|
422
|
+
position=position,
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def scale_y_log2(name=None, *,
|
|
427
|
+
breaks=None, labels=None, lablim=None,
|
|
428
|
+
limits=None,
|
|
429
|
+
expand=None,
|
|
430
|
+
na_value=None,
|
|
431
|
+
format=None,
|
|
432
|
+
position=None
|
|
433
|
+
):
|
|
434
|
+
"""
|
|
435
|
+
Continuous position scales y where trans='log2'.
|
|
436
|
+
|
|
437
|
+
Parameters
|
|
438
|
+
----------
|
|
439
|
+
name : str
|
|
440
|
+
The name of the scale - used as the axis label or the legend title.
|
|
441
|
+
If None, the default, the name of the scale
|
|
442
|
+
is taken from the first mapping used for that aesthetic.
|
|
443
|
+
breaks : list or dict
|
|
444
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
445
|
+
labels : list of str or dict
|
|
446
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
447
|
+
lablim : int, default=None
|
|
448
|
+
The maximum label length (in characters) before trimming is applied.
|
|
449
|
+
limits : list
|
|
450
|
+
A numeric vector of length two providing limits of the scale.
|
|
451
|
+
expand : list
|
|
452
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
453
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
454
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
455
|
+
na_value
|
|
456
|
+
Missing values will be replaced with this value.
|
|
457
|
+
format : str
|
|
458
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
459
|
+
|
|
460
|
+
- '.2f' -> '12.45'
|
|
461
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
462
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
463
|
+
|
|
464
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
465
|
+
position : str
|
|
466
|
+
The position of the axis:
|
|
467
|
+
|
|
468
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
469
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
470
|
+
|
|
471
|
+
Returns
|
|
472
|
+
-------
|
|
473
|
+
``FeatureSpec``
|
|
474
|
+
Scale specification.
|
|
475
|
+
|
|
476
|
+
Examples
|
|
477
|
+
--------
|
|
478
|
+
.. jupyter-execute::
|
|
479
|
+
:linenos:
|
|
480
|
+
:emphasize-lines: 6
|
|
481
|
+
|
|
482
|
+
import numpy as np
|
|
483
|
+
from lets_plot import *
|
|
484
|
+
LetsPlot.setup_html()
|
|
485
|
+
np.random.seed(42)
|
|
486
|
+
x = np.random.poisson(size=100)
|
|
487
|
+
ggplot({'x': x}, aes(x='x')) + geom_histogram() + scale_y_log2()
|
|
488
|
+
|
|
489
|
+
"""
|
|
490
|
+
return scale_y_continuous(name,
|
|
491
|
+
breaks=breaks,
|
|
492
|
+
labels=labels,
|
|
493
|
+
lablim=lablim,
|
|
494
|
+
limits=limits,
|
|
495
|
+
expand=expand,
|
|
496
|
+
na_value=na_value,
|
|
497
|
+
trans='log2',
|
|
498
|
+
format=format,
|
|
499
|
+
position=position,
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
def scale_x_reverse(name=None, *,
|
|
504
|
+
breaks=None, labels=None, lablim=None,
|
|
505
|
+
limits=None,
|
|
506
|
+
expand=None,
|
|
507
|
+
na_value=None,
|
|
508
|
+
format=None,
|
|
509
|
+
position=None
|
|
510
|
+
):
|
|
511
|
+
"""
|
|
512
|
+
Continuous position scale x where trans='reverse'.
|
|
513
|
+
|
|
514
|
+
Parameters
|
|
515
|
+
----------
|
|
516
|
+
name : str
|
|
517
|
+
The name of the scale - used as the axis label or the legend title.
|
|
518
|
+
If None, the default, the name of the scale
|
|
519
|
+
is taken from the first mapping used for that aesthetic.
|
|
520
|
+
breaks : list or dict
|
|
521
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
522
|
+
labels : list of str or dict
|
|
523
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
524
|
+
lablim : int, default=None
|
|
525
|
+
The maximum label length (in characters) before trimming is applied.
|
|
526
|
+
limits : list
|
|
527
|
+
A numeric vector of length two providing limits of the scale.
|
|
528
|
+
expand : list
|
|
529
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
530
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
531
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
532
|
+
na_value
|
|
533
|
+
Missing values will be replaced with this value.
|
|
534
|
+
format : str
|
|
535
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
536
|
+
|
|
537
|
+
- '.2f' -> '12.45'
|
|
538
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
539
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
540
|
+
|
|
541
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
542
|
+
position : str
|
|
543
|
+
The position of the axis:
|
|
544
|
+
|
|
545
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
546
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
547
|
+
|
|
548
|
+
Returns
|
|
549
|
+
-------
|
|
550
|
+
``FeatureSpec``
|
|
551
|
+
Scale specification.
|
|
552
|
+
|
|
553
|
+
Examples
|
|
554
|
+
--------
|
|
555
|
+
.. jupyter-execute::
|
|
556
|
+
:linenos:
|
|
557
|
+
:emphasize-lines: 5
|
|
558
|
+
|
|
559
|
+
from lets_plot import *
|
|
560
|
+
LetsPlot.setup_html()
|
|
561
|
+
x = list(range(10))
|
|
562
|
+
ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
|
|
563
|
+
geom_point() + scale_x_reverse()
|
|
564
|
+
|
|
565
|
+
"""
|
|
566
|
+
|
|
567
|
+
return scale_x_continuous(name,
|
|
568
|
+
breaks=breaks,
|
|
569
|
+
labels=labels,
|
|
570
|
+
lablim=lablim,
|
|
571
|
+
limits=limits,
|
|
572
|
+
expand=expand,
|
|
573
|
+
na_value=na_value,
|
|
574
|
+
trans='reverse',
|
|
575
|
+
format=format,
|
|
576
|
+
position=position,
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def scale_y_reverse(name=None, *,
|
|
581
|
+
breaks=None, labels=None, lablim=None,
|
|
582
|
+
limits=None,
|
|
583
|
+
expand=None,
|
|
584
|
+
na_value=None,
|
|
585
|
+
format=None,
|
|
586
|
+
position=None
|
|
587
|
+
):
|
|
588
|
+
"""
|
|
589
|
+
Continuous position scale y where trans='reverse'.
|
|
590
|
+
|
|
591
|
+
Parameters
|
|
592
|
+
----------
|
|
593
|
+
name : str
|
|
594
|
+
The name of the scale - used as the axis label or the legend title.
|
|
595
|
+
If None, the default, the name of the scale
|
|
596
|
+
is taken from the first mapping used for that aesthetic.
|
|
597
|
+
breaks : list or dict
|
|
598
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
599
|
+
labels : list of str or dict
|
|
600
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
601
|
+
lablim : int, default=None
|
|
602
|
+
The maximum label length (in characters) before trimming is applied.
|
|
603
|
+
limits : list
|
|
604
|
+
A numeric vector of length two providing limits of the scale.
|
|
605
|
+
expand : list
|
|
606
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
607
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
608
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
609
|
+
na_value
|
|
610
|
+
Missing values will be replaced with this value.
|
|
611
|
+
format : str
|
|
612
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
613
|
+
|
|
614
|
+
- '.2f' -> '12.45'
|
|
615
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
616
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
617
|
+
|
|
618
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
619
|
+
position : str
|
|
620
|
+
The position of the axis:
|
|
621
|
+
|
|
622
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
623
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
624
|
+
|
|
625
|
+
Returns
|
|
626
|
+
-------
|
|
627
|
+
``FeatureSpec``
|
|
628
|
+
Scale specification.
|
|
629
|
+
|
|
630
|
+
Examples
|
|
631
|
+
--------
|
|
632
|
+
.. jupyter-execute::
|
|
633
|
+
:linenos:
|
|
634
|
+
:emphasize-lines: 5
|
|
635
|
+
|
|
636
|
+
from lets_plot import *
|
|
637
|
+
LetsPlot.setup_html()
|
|
638
|
+
x = list(range(10))
|
|
639
|
+
ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
|
|
640
|
+
geom_point() + scale_y_reverse(limits=[2, 6])
|
|
641
|
+
|
|
642
|
+
"""
|
|
643
|
+
|
|
644
|
+
return scale_y_continuous(name,
|
|
645
|
+
breaks=breaks,
|
|
646
|
+
labels=labels,
|
|
647
|
+
lablim=lablim,
|
|
648
|
+
limits=limits,
|
|
649
|
+
expand=expand,
|
|
650
|
+
na_value=na_value,
|
|
651
|
+
trans='reverse',
|
|
652
|
+
format=format,
|
|
653
|
+
position=position,
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
#
|
|
658
|
+
# Discrete Scales
|
|
659
|
+
#
|
|
660
|
+
|
|
661
|
+
def scale_x_discrete(name=None, *,
|
|
662
|
+
breaks=None, labels=None, lablim=None,
|
|
663
|
+
limits=None,
|
|
664
|
+
expand=None,
|
|
665
|
+
na_value=None,
|
|
666
|
+
reverse=None,
|
|
667
|
+
format=None,
|
|
668
|
+
position=None
|
|
669
|
+
):
|
|
670
|
+
"""
|
|
671
|
+
Discrete position scale x.
|
|
672
|
+
|
|
673
|
+
Parameters
|
|
674
|
+
----------
|
|
675
|
+
name : str
|
|
676
|
+
The name of the scale - used as the axis label or the legend title.
|
|
677
|
+
If None, the default, the name of the scale
|
|
678
|
+
is taken from the first mapping used for that aesthetic.
|
|
679
|
+
breaks : list or dict
|
|
680
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
681
|
+
labels : list of str or dict
|
|
682
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
683
|
+
lablim : int, default=None
|
|
684
|
+
The maximum label length (in characters) before trimming is applied.
|
|
685
|
+
limits : list
|
|
686
|
+
A vector specifying the data range for the scale and the default order of their display in guides.
|
|
687
|
+
expand : list
|
|
688
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
689
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
690
|
+
Defaults: multiplicative = 0, additive = 0.2.
|
|
691
|
+
na_value
|
|
692
|
+
Missing values will be replaced with this value.
|
|
693
|
+
reverse : bool
|
|
694
|
+
When True the scale is reversed.
|
|
695
|
+
format : str
|
|
696
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
697
|
+
|
|
698
|
+
- '.2f' -> '12.45'
|
|
699
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
700
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
701
|
+
|
|
702
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
703
|
+
position : str
|
|
704
|
+
The position of the axis:
|
|
705
|
+
|
|
706
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
707
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
708
|
+
|
|
709
|
+
Returns
|
|
710
|
+
-------
|
|
711
|
+
``FeatureSpec``
|
|
712
|
+
Scale specification.
|
|
713
|
+
|
|
714
|
+
Examples
|
|
715
|
+
--------
|
|
716
|
+
.. jupyter-execute::
|
|
717
|
+
:linenos:
|
|
718
|
+
:emphasize-lines: 7
|
|
719
|
+
|
|
720
|
+
import numpy as np
|
|
721
|
+
from lets_plot import *
|
|
722
|
+
LetsPlot.setup_html()
|
|
723
|
+
np.random.seed(43)
|
|
724
|
+
scores = {'rating': np.random.randint(3, 6, size=10)}
|
|
725
|
+
ggplot(scores, aes(x=as_discrete('rating'))) + geom_bar() + \\
|
|
726
|
+
scale_x_discrete(name='rating', format='.1f')
|
|
727
|
+
|
|
728
|
+
"""
|
|
729
|
+
|
|
730
|
+
reverse = as_boolean(reverse, default=False)
|
|
731
|
+
return _scale('x',
|
|
732
|
+
name=name,
|
|
733
|
+
breaks=breaks,
|
|
734
|
+
labels=labels,
|
|
735
|
+
lablim=lablim,
|
|
736
|
+
limits=limits,
|
|
737
|
+
expand=expand,
|
|
738
|
+
na_value=na_value,
|
|
739
|
+
trans=None,
|
|
740
|
+
guide=None,
|
|
741
|
+
format=format,
|
|
742
|
+
position=position,
|
|
743
|
+
#
|
|
744
|
+
discrete=True,
|
|
745
|
+
reverse=reverse
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
def scale_x_discrete_reversed(name=None, *,
|
|
750
|
+
breaks=None, labels=None, lablim=None,
|
|
751
|
+
limits=None,
|
|
752
|
+
expand=None,
|
|
753
|
+
na_value=None,
|
|
754
|
+
format=None,
|
|
755
|
+
position=None
|
|
756
|
+
):
|
|
757
|
+
"""
|
|
758
|
+
Reversed discrete position scale x.
|
|
759
|
+
|
|
760
|
+
Parameters
|
|
761
|
+
----------
|
|
762
|
+
name : str
|
|
763
|
+
The name of the scale - used as the axis label or the legend title.
|
|
764
|
+
If None, the default, the name of the scale
|
|
765
|
+
is taken from the first mapping used for that aesthetic.
|
|
766
|
+
breaks : list or dict
|
|
767
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
768
|
+
labels : list of str or dict
|
|
769
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
770
|
+
lablim : int, default=None
|
|
771
|
+
The maximum label length (in characters) before trimming is applied.
|
|
772
|
+
limits : list
|
|
773
|
+
A vector specifying the data range for the scale and the default order of their display in guides.
|
|
774
|
+
expand : list
|
|
775
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
776
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
777
|
+
Defaults: multiplicative = 0, additive = 0.2.
|
|
778
|
+
na_value
|
|
779
|
+
Missing values will be replaced with this value.
|
|
780
|
+
format : str
|
|
781
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
782
|
+
|
|
783
|
+
- '.2f' -> '12.45'
|
|
784
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
785
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
786
|
+
|
|
787
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
788
|
+
position : str
|
|
789
|
+
The position of the axis:
|
|
790
|
+
|
|
791
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
792
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
793
|
+
|
|
794
|
+
Returns
|
|
795
|
+
-------
|
|
796
|
+
``FeatureSpec``
|
|
797
|
+
Scale specification.
|
|
798
|
+
|
|
799
|
+
Examples
|
|
800
|
+
--------
|
|
801
|
+
.. jupyter-execute::
|
|
802
|
+
:linenos:
|
|
803
|
+
:emphasize-lines: 8
|
|
804
|
+
|
|
805
|
+
from lets_plot import *
|
|
806
|
+
LetsPlot.setup_html()
|
|
807
|
+
data = {
|
|
808
|
+
'time': ['Lunch', 'Dinner', 'Night'],
|
|
809
|
+
'bill': [15.5, 18.13, 30],
|
|
810
|
+
}
|
|
811
|
+
ggplot(data, aes('time', 'bill')) + geom_bar(stat='identity') + \\
|
|
812
|
+
scale_x_discrete_reversed()
|
|
813
|
+
|
|
814
|
+
"""
|
|
815
|
+
|
|
816
|
+
return scale_x_discrete(name,
|
|
817
|
+
breaks=breaks,
|
|
818
|
+
labels=labels,
|
|
819
|
+
lablim=lablim,
|
|
820
|
+
limits=limits,
|
|
821
|
+
expand=expand,
|
|
822
|
+
na_value=na_value,
|
|
823
|
+
format=format,
|
|
824
|
+
position=position,
|
|
825
|
+
#
|
|
826
|
+
reverse=True,
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
def scale_y_discrete(name=None, *,
|
|
831
|
+
breaks=None, labels=None, lablim=None,
|
|
832
|
+
limits=None,
|
|
833
|
+
expand=None,
|
|
834
|
+
na_value=None,
|
|
835
|
+
reverse=None,
|
|
836
|
+
format=None,
|
|
837
|
+
position=None,
|
|
838
|
+
):
|
|
839
|
+
"""
|
|
840
|
+
Discrete position scale y.
|
|
841
|
+
|
|
842
|
+
Parameters
|
|
843
|
+
----------
|
|
844
|
+
name : str
|
|
845
|
+
The name of the scale - used as the axis label or the legend title.
|
|
846
|
+
If None, the default, the name of the scale
|
|
847
|
+
is taken from the first mapping used for that aesthetic.
|
|
848
|
+
breaks : list or dict
|
|
849
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
850
|
+
labels : list of str or dict
|
|
851
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
852
|
+
lablim : int, default=None
|
|
853
|
+
The maximum label length (in characters) before trimming is applied.
|
|
854
|
+
limits : list
|
|
855
|
+
A vector specifying the data range for the scale and the default order of their display in guides.
|
|
856
|
+
expand : list
|
|
857
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
858
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
859
|
+
Defaults: multiplicative = 0, additive = 0.2.
|
|
860
|
+
na_value
|
|
861
|
+
Missing values will be replaced with this value.
|
|
862
|
+
reverse : bool
|
|
863
|
+
When True the scale is reversed.
|
|
864
|
+
format : str
|
|
865
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
866
|
+
|
|
867
|
+
- '.2f' -> '12.45'
|
|
868
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
869
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
870
|
+
|
|
871
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
872
|
+
position : str
|
|
873
|
+
The position of the axis:
|
|
874
|
+
|
|
875
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
876
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
877
|
+
|
|
878
|
+
Returns
|
|
879
|
+
-------
|
|
880
|
+
``FeatureSpec``
|
|
881
|
+
Scale specification.
|
|
882
|
+
|
|
883
|
+
Examples
|
|
884
|
+
--------
|
|
885
|
+
.. jupyter-execute::
|
|
886
|
+
:linenos:
|
|
887
|
+
:emphasize-lines: 8
|
|
888
|
+
|
|
889
|
+
from lets_plot import *
|
|
890
|
+
LetsPlot.setup_html()
|
|
891
|
+
data = {
|
|
892
|
+
'time': ['Breakfast', 'Lunch', 'Dinner', 'Night'],
|
|
893
|
+
'bill': [3.25, 15.5, 18.3, 30],
|
|
894
|
+
}
|
|
895
|
+
ggplot(data, aes('bill', 'time')) + geom_point(size=5) + \\
|
|
896
|
+
scale_y_discrete(limits=['Lunch', 'Dinner', 'Night'])
|
|
897
|
+
|
|
898
|
+
"""
|
|
899
|
+
reverse = as_boolean(reverse, default=False)
|
|
900
|
+
return _scale('y',
|
|
901
|
+
name=name,
|
|
902
|
+
breaks=breaks,
|
|
903
|
+
labels=labels,
|
|
904
|
+
lablim=lablim,
|
|
905
|
+
limits=limits,
|
|
906
|
+
expand=expand,
|
|
907
|
+
na_value=na_value,
|
|
908
|
+
trans=None,
|
|
909
|
+
guide=None,
|
|
910
|
+
format=format,
|
|
911
|
+
position=position,
|
|
912
|
+
#
|
|
913
|
+
discrete=True,
|
|
914
|
+
reverse=reverse
|
|
915
|
+
)
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
def scale_y_discrete_reversed(name=None, *,
|
|
919
|
+
breaks=None, labels=None, lablim=None,
|
|
920
|
+
limits=None,
|
|
921
|
+
expand=None,
|
|
922
|
+
na_value=None,
|
|
923
|
+
format=None,
|
|
924
|
+
position=None
|
|
925
|
+
):
|
|
926
|
+
"""
|
|
927
|
+
Reversed discrete position scale y.
|
|
928
|
+
|
|
929
|
+
Parameters
|
|
930
|
+
----------
|
|
931
|
+
name : str
|
|
932
|
+
The name of the scale - used as the axis label or the legend title.
|
|
933
|
+
If None, the default, the name of the scale
|
|
934
|
+
is taken from the first mapping used for that aesthetic.
|
|
935
|
+
breaks : list or dict
|
|
936
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
937
|
+
labels : list of str or dict
|
|
938
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
939
|
+
lablim : int, default=None
|
|
940
|
+
The maximum label length (in characters) before trimming is applied.
|
|
941
|
+
limits : list
|
|
942
|
+
A vector specifying the data range for the scale and the default order of their display in guides.
|
|
943
|
+
expand : list of two numbers
|
|
944
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
945
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
946
|
+
Defaults: multiplicative = 0, additive = 0.2.
|
|
947
|
+
na_value
|
|
948
|
+
Missing values will be replaced with this value.
|
|
949
|
+
format : str
|
|
950
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
951
|
+
|
|
952
|
+
- '.2f' -> '12.45'
|
|
953
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
954
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
955
|
+
|
|
956
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
957
|
+
position : str
|
|
958
|
+
The position of the axis:
|
|
959
|
+
|
|
960
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
961
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
962
|
+
|
|
963
|
+
Returns
|
|
964
|
+
-------
|
|
965
|
+
``FeatureSpec``
|
|
966
|
+
Scale specification.
|
|
967
|
+
|
|
968
|
+
Examples
|
|
969
|
+
--------
|
|
970
|
+
.. jupyter-execute::
|
|
971
|
+
:linenos:
|
|
972
|
+
:emphasize-lines: 8
|
|
973
|
+
|
|
974
|
+
from lets_plot import *
|
|
975
|
+
LetsPlot.setup_html()
|
|
976
|
+
data = {
|
|
977
|
+
'time': ['Breakfast', 'Lunch', 'Dinner', 'Night'],
|
|
978
|
+
'bill': [3.25, 15.5, 18.3, 30],
|
|
979
|
+
}
|
|
980
|
+
ggplot(data, aes('bill', 'time')) + geom_line() + \\
|
|
981
|
+
scale_y_discrete_reversed()
|
|
982
|
+
|
|
983
|
+
"""
|
|
984
|
+
|
|
985
|
+
return scale_y_discrete(name,
|
|
986
|
+
breaks=breaks,
|
|
987
|
+
labels=labels,
|
|
988
|
+
lablim=lablim,
|
|
989
|
+
limits=limits,
|
|
990
|
+
expand=expand,
|
|
991
|
+
na_value=na_value,
|
|
992
|
+
format=format,
|
|
993
|
+
position=position,
|
|
994
|
+
#
|
|
995
|
+
reverse=True,
|
|
996
|
+
)
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
#
|
|
1000
|
+
# Date-time
|
|
1001
|
+
#
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
def scale_x_datetime(name=None, *,
|
|
1005
|
+
breaks=None,
|
|
1006
|
+
labels=None,
|
|
1007
|
+
lablim=None,
|
|
1008
|
+
limits=None,
|
|
1009
|
+
expand=None,
|
|
1010
|
+
na_value=None,
|
|
1011
|
+
format=None,
|
|
1012
|
+
position=None
|
|
1013
|
+
):
|
|
1014
|
+
"""
|
|
1015
|
+
Position scale for the x-axis with date/time data.
|
|
1016
|
+
The input is expected to be either a series of integers representing milliseconds since the Unix epoch, or Python datetime objects.
|
|
1017
|
+
Assumes UTC timezone if no timezone information is present in the data (naive datetime).
|
|
1018
|
+
For timezone-aware datetime objects, the timezone information from the data is preserved.
|
|
1019
|
+
|
|
1020
|
+
Parameters
|
|
1021
|
+
----------
|
|
1022
|
+
name : str
|
|
1023
|
+
The name of the scale - used as the axis label or the legend title.
|
|
1024
|
+
If None, the default, the name of the scale
|
|
1025
|
+
is taken from the first mapping used for that aesthetic.
|
|
1026
|
+
breaks : list or dict
|
|
1027
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
1028
|
+
labels : list of str or dict
|
|
1029
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
1030
|
+
lablim : int, default=None
|
|
1031
|
+
The maximum label length (in characters) before trimming is applied.
|
|
1032
|
+
limits : list
|
|
1033
|
+
A vector of length two providing limits of the scale.
|
|
1034
|
+
expand : list
|
|
1035
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
1036
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
1037
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
1038
|
+
na_value
|
|
1039
|
+
Missing values will be replaced with this value.
|
|
1040
|
+
format : str
|
|
1041
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
1042
|
+
|
|
1043
|
+
- '%d.%m.%y' -> '06.08.19'
|
|
1044
|
+
- '%B %Y' -> 'August 2019'
|
|
1045
|
+
- '%a, %e %b %Y %H:%M:%S' -> 'Tue, 6 Aug 2019 04:46:35'
|
|
1046
|
+
|
|
1047
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
1048
|
+
position : str
|
|
1049
|
+
The position of the axis:
|
|
1050
|
+
|
|
1051
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
1052
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
1053
|
+
|
|
1054
|
+
Returns
|
|
1055
|
+
-------
|
|
1056
|
+
``FeatureSpec``
|
|
1057
|
+
Scale specification.
|
|
1058
|
+
|
|
1059
|
+
Examples
|
|
1060
|
+
--------
|
|
1061
|
+
.. jupyter-execute::
|
|
1062
|
+
:linenos:
|
|
1063
|
+
:emphasize-lines: 12
|
|
1064
|
+
|
|
1065
|
+
import datetime as dt
|
|
1066
|
+
import numpy as np
|
|
1067
|
+
from lets_plot import *
|
|
1068
|
+
LetsPlot.setup_html()
|
|
1069
|
+
n = 31
|
|
1070
|
+
np.random.seed(42)
|
|
1071
|
+
d = [dt.datetime(2021, 1, 1) + dt.timedelta(days=d)
|
|
1072
|
+
for d in range(n)]
|
|
1073
|
+
t = np.random.normal(loc=-5, scale=6, size=n)
|
|
1074
|
+
ggplot({'d': d, 't': t}, aes('d', 't')) + \\
|
|
1075
|
+
geom_histogram(aes(fill='t'), stat='identity', color='black') + \\
|
|
1076
|
+
scale_x_datetime() + \\
|
|
1077
|
+
scale_fill_gradient2(low='#2c7bb6', high='#d7191c')
|
|
1078
|
+
|
|
1079
|
+
"""
|
|
1080
|
+
return _scale('x',
|
|
1081
|
+
name=name,
|
|
1082
|
+
breaks=breaks,
|
|
1083
|
+
labels=labels,
|
|
1084
|
+
lablim=lablim,
|
|
1085
|
+
limits=limits,
|
|
1086
|
+
expand=expand,
|
|
1087
|
+
na_value=na_value,
|
|
1088
|
+
trans=None,
|
|
1089
|
+
guide=None,
|
|
1090
|
+
format=format,
|
|
1091
|
+
position=position,
|
|
1092
|
+
#
|
|
1093
|
+
datetime=True)
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
def scale_y_datetime(name=None, *,
|
|
1097
|
+
breaks=None, labels=None, lablim=None,
|
|
1098
|
+
limits=None,
|
|
1099
|
+
expand=None,
|
|
1100
|
+
na_value=None,
|
|
1101
|
+
format=None,
|
|
1102
|
+
position=None
|
|
1103
|
+
):
|
|
1104
|
+
"""
|
|
1105
|
+
Position scale for the y-axis with date/time data.
|
|
1106
|
+
The input is expected to be either a series of integers representing milliseconds since the Unix epoch, or Python datetime objects.
|
|
1107
|
+
Assumes UTC timezone if no timezone information is present in the data (naive datetime).
|
|
1108
|
+
For timezone-aware datetime objects, the timezone information from the data is preserved.
|
|
1109
|
+
|
|
1110
|
+
Parameters
|
|
1111
|
+
----------
|
|
1112
|
+
name : str
|
|
1113
|
+
The name of the scale - used as the axis label or the legend title.
|
|
1114
|
+
If None, the default, the name of the scale
|
|
1115
|
+
is taken from the first mapping used for that aesthetic.
|
|
1116
|
+
breaks : list or dict
|
|
1117
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
1118
|
+
labels : list of str or dict
|
|
1119
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
1120
|
+
lablim : int, default=None
|
|
1121
|
+
The maximum label length (in characters) before trimming is applied.
|
|
1122
|
+
limits : list
|
|
1123
|
+
A vector of length two providing limits of the scale.
|
|
1124
|
+
expand : list of two numbers
|
|
1125
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
1126
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
1127
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
1128
|
+
na_value
|
|
1129
|
+
Missing values will be replaced with this value.
|
|
1130
|
+
format : str
|
|
1131
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
1132
|
+
|
|
1133
|
+
- '%d.%m.%y' -> '06.08.19'
|
|
1134
|
+
- '%B %Y' -> 'August 2019'
|
|
1135
|
+
- '%a, %e %b %Y %H:%M:%S' -> 'Tue, 6 Aug 2019 04:46:35'
|
|
1136
|
+
|
|
1137
|
+
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
|
|
1138
|
+
position : str
|
|
1139
|
+
The position of the axis:
|
|
1140
|
+
|
|
1141
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
1142
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
1143
|
+
|
|
1144
|
+
Returns
|
|
1145
|
+
-------
|
|
1146
|
+
``FeatureSpec``
|
|
1147
|
+
Scale specification.
|
|
1148
|
+
|
|
1149
|
+
Examples
|
|
1150
|
+
--------
|
|
1151
|
+
.. jupyter-execute::
|
|
1152
|
+
:linenos:
|
|
1153
|
+
:emphasize-lines: 13
|
|
1154
|
+
|
|
1155
|
+
import datetime as dt
|
|
1156
|
+
from lets_plot import *
|
|
1157
|
+
LetsPlot.setup_html()
|
|
1158
|
+
n = 12
|
|
1159
|
+
rcount = lambda m: 1 if m < 2 else rcount(m - 1) + rcount(m - 2)
|
|
1160
|
+
data = {
|
|
1161
|
+
'date': [dt.datetime(2020, m, 1) for m in range(1, n + 1)],
|
|
1162
|
+
'rabbits count': [rcount(m) for m in range(1, n + 1)],
|
|
1163
|
+
}
|
|
1164
|
+
ggplot(data) + \\
|
|
1165
|
+
geom_segment(aes(x=[0] * n, y='date', xend='rabbits count', yend='date'), size=3, \\
|
|
1166
|
+
tooltips=layer_tooltips().line('@|@{rabbits count}')) + \\
|
|
1167
|
+
scale_y_datetime(format='%b') + \\
|
|
1168
|
+
xlab('rabbits count')
|
|
1169
|
+
|
|
1170
|
+
"""
|
|
1171
|
+
return _scale('y',
|
|
1172
|
+
name=name,
|
|
1173
|
+
breaks=breaks,
|
|
1174
|
+
labels=labels,
|
|
1175
|
+
lablim=lablim,
|
|
1176
|
+
limits=limits,
|
|
1177
|
+
expand=expand,
|
|
1178
|
+
na_value=na_value,
|
|
1179
|
+
trans=None,
|
|
1180
|
+
guide=None,
|
|
1181
|
+
format=format,
|
|
1182
|
+
position=position,
|
|
1183
|
+
#
|
|
1184
|
+
datetime=True)
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
def scale_x_time(name=None, *,
|
|
1188
|
+
breaks=None, labels=None, lablim=None,
|
|
1189
|
+
limits=None,
|
|
1190
|
+
expand=None,
|
|
1191
|
+
na_value=None,
|
|
1192
|
+
# format=None,
|
|
1193
|
+
position=None
|
|
1194
|
+
):
|
|
1195
|
+
"""
|
|
1196
|
+
Position scale x for data representing "time delta" values expressed in milliseconds.
|
|
1197
|
+
|
|
1198
|
+
Parameters
|
|
1199
|
+
----------
|
|
1200
|
+
name : str
|
|
1201
|
+
The name of the scale - used as the axis label or the legend title.
|
|
1202
|
+
If None, the default, the name of the scale
|
|
1203
|
+
is taken from the first mapping used for that aesthetic.
|
|
1204
|
+
breaks : list or dict
|
|
1205
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
1206
|
+
labels : list of str or dict
|
|
1207
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
1208
|
+
lablim : int, default=None
|
|
1209
|
+
The maximum label length (in characters) before trimming is applied.
|
|
1210
|
+
limits : list
|
|
1211
|
+
A numeric vector of length two providing limits of the scale.
|
|
1212
|
+
expand : list
|
|
1213
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
1214
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
1215
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
1216
|
+
na_value
|
|
1217
|
+
Missing values will be replaced with this value.
|
|
1218
|
+
position : str
|
|
1219
|
+
The position of the axis:
|
|
1220
|
+
|
|
1221
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
1222
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
1223
|
+
|
|
1224
|
+
Returns
|
|
1225
|
+
-------
|
|
1226
|
+
``FeatureSpec``
|
|
1227
|
+
Scale specification.
|
|
1228
|
+
|
|
1229
|
+
Examples
|
|
1230
|
+
--------
|
|
1231
|
+
.. jupyter-execute::
|
|
1232
|
+
:linenos:
|
|
1233
|
+
:emphasize-lines: 13
|
|
1234
|
+
|
|
1235
|
+
import datetime as dt
|
|
1236
|
+
import numpy as np
|
|
1237
|
+
from lets_plot import *
|
|
1238
|
+
LetsPlot.setup_html()
|
|
1239
|
+
n = 31
|
|
1240
|
+
np.random.seed(42)
|
|
1241
|
+
data = {
|
|
1242
|
+
'time': [dt.timedelta(days=v).total_seconds() * 1000 for v in range(n)],
|
|
1243
|
+
'value': np.random.normal(loc=-5, scale=6, size=n)
|
|
1244
|
+
}
|
|
1245
|
+
ggplot(data) + \\
|
|
1246
|
+
geom_line(aes('time', 'value')) + \\
|
|
1247
|
+
scale_x_time()
|
|
1248
|
+
|
|
1249
|
+
"""
|
|
1250
|
+
return _scale('x',
|
|
1251
|
+
name=name,
|
|
1252
|
+
breaks=breaks,
|
|
1253
|
+
labels=labels,
|
|
1254
|
+
lablim=lablim,
|
|
1255
|
+
limits=limits,
|
|
1256
|
+
expand=expand,
|
|
1257
|
+
na_value=na_value,
|
|
1258
|
+
trans=None,
|
|
1259
|
+
guide=None,
|
|
1260
|
+
# format=format,
|
|
1261
|
+
position=position,
|
|
1262
|
+
#
|
|
1263
|
+
time=True)
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
def scale_y_time(name=None, *,
|
|
1267
|
+
breaks=None, labels=None, lablim=None,
|
|
1268
|
+
limits=None,
|
|
1269
|
+
expand=None,
|
|
1270
|
+
na_value=None,
|
|
1271
|
+
# format=None,
|
|
1272
|
+
position=None
|
|
1273
|
+
):
|
|
1274
|
+
"""
|
|
1275
|
+
Position scale y for data representing "time delta" values expressed in milliseconds.
|
|
1276
|
+
|
|
1277
|
+
Parameters
|
|
1278
|
+
----------
|
|
1279
|
+
name : str
|
|
1280
|
+
The name of the scale - used as the axis label or the legend title.
|
|
1281
|
+
If None, the default, the name of the scale
|
|
1282
|
+
is taken from the first mapping used for that aesthetic.
|
|
1283
|
+
breaks : list or dict
|
|
1284
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
1285
|
+
labels : list of str or dict
|
|
1286
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
1287
|
+
lablim : int, default=None
|
|
1288
|
+
The maximum label length (in characters) before trimming is applied.
|
|
1289
|
+
limits : list
|
|
1290
|
+
A numeric vector of length two providing limits of the scale.
|
|
1291
|
+
expand : list
|
|
1292
|
+
A numeric vector of length two giving multiplicative and additive expansion constants.
|
|
1293
|
+
The vector size == 1 => only multiplicative expand (and additive expand by default).
|
|
1294
|
+
Defaults: multiplicative = 0.05, additive = 0.
|
|
1295
|
+
na_value
|
|
1296
|
+
Missing values will be replaced with this value.
|
|
1297
|
+
position : str
|
|
1298
|
+
The position of the axis:
|
|
1299
|
+
|
|
1300
|
+
- 'left', 'right' or 'both' for y-axis;
|
|
1301
|
+
- 'top', 'bottom' or 'both' for x-axis.
|
|
1302
|
+
|
|
1303
|
+
Returns
|
|
1304
|
+
-------
|
|
1305
|
+
``FeatureSpec``
|
|
1306
|
+
Scale specification.
|
|
1307
|
+
|
|
1308
|
+
Examples
|
|
1309
|
+
--------
|
|
1310
|
+
.. jupyter-execute::
|
|
1311
|
+
:linenos:
|
|
1312
|
+
:emphasize-lines: 13
|
|
1313
|
+
|
|
1314
|
+
import datetime as dt
|
|
1315
|
+
import numpy as np
|
|
1316
|
+
from lets_plot import *
|
|
1317
|
+
LetsPlot.setup_html()
|
|
1318
|
+
n = 31
|
|
1319
|
+
np.random.seed(42)
|
|
1320
|
+
data = {
|
|
1321
|
+
'time': [dt.timedelta(days=v).total_seconds() * 1000 for v in range(n)],
|
|
1322
|
+
'value': np.random.normal(loc=-5, scale=6, size=n)
|
|
1323
|
+
}
|
|
1324
|
+
ggplot(data) + \\
|
|
1325
|
+
geom_line(aes('value', 'time')) + \\
|
|
1326
|
+
scale_y_time()
|
|
1327
|
+
|
|
1328
|
+
"""
|
|
1329
|
+
return _scale('y',
|
|
1330
|
+
name=name,
|
|
1331
|
+
breaks=breaks,
|
|
1332
|
+
labels=labels,
|
|
1333
|
+
lablim=lablim,
|
|
1334
|
+
limits=limits,
|
|
1335
|
+
expand=expand,
|
|
1336
|
+
na_value=na_value,
|
|
1337
|
+
trans=None,
|
|
1338
|
+
guide=None,
|
|
1339
|
+
# format=format,
|
|
1340
|
+
position=position,
|
|
1341
|
+
#
|
|
1342
|
+
time=True)
|