lets-plot 4.5.0__cp313-cp313-win_amd64.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.

Potentially problematic release.


This version of lets-plot might be problematic. Click here for more details.

Files changed (89) hide show
  1. lets_plot/__init__.py +283 -0
  2. lets_plot/_global_settings.py +191 -0
  3. lets_plot/_kbridge.py +36 -0
  4. lets_plot/_type_utils.py +110 -0
  5. lets_plot/_version.py +6 -0
  6. lets_plot/bistro/__init__.py +16 -0
  7. lets_plot/bistro/_plot2d_common.py +93 -0
  8. lets_plot/bistro/corr.py +447 -0
  9. lets_plot/bistro/im.py +165 -0
  10. lets_plot/bistro/joint.py +192 -0
  11. lets_plot/bistro/qq.py +207 -0
  12. lets_plot/bistro/residual.py +341 -0
  13. lets_plot/bistro/waterfall.py +250 -0
  14. lets_plot/export/__init__.py +6 -0
  15. lets_plot/export/ggsave_.py +133 -0
  16. lets_plot/frontend_context/__init__.py +8 -0
  17. lets_plot/frontend_context/_configuration.py +144 -0
  18. lets_plot/frontend_context/_frontend_ctx.py +16 -0
  19. lets_plot/frontend_context/_html_contexts.py +117 -0
  20. lets_plot/frontend_context/_intellij_python_json_ctx.py +38 -0
  21. lets_plot/frontend_context/_json_contexts.py +39 -0
  22. lets_plot/frontend_context/_jupyter_notebook_ctx.py +119 -0
  23. lets_plot/frontend_context/_mime_types.py +7 -0
  24. lets_plot/frontend_context/_static_html_page_ctx.py +27 -0
  25. lets_plot/frontend_context/_static_svg_ctx.py +26 -0
  26. lets_plot/frontend_context/_webbr_html_page_ctx.py +29 -0
  27. lets_plot/frontend_context/sandbox.py +5 -0
  28. lets_plot/geo_data/__init__.py +18 -0
  29. lets_plot/geo_data/core.py +331 -0
  30. lets_plot/geo_data/geocoder.py +977 -0
  31. lets_plot/geo_data/geocodes.py +512 -0
  32. lets_plot/geo_data/gis/__init__.py +0 -0
  33. lets_plot/geo_data/gis/fluent_dict.py +201 -0
  34. lets_plot/geo_data/gis/geocoding_service.py +42 -0
  35. lets_plot/geo_data/gis/geometry.py +91 -0
  36. lets_plot/geo_data/gis/json_request.py +232 -0
  37. lets_plot/geo_data/gis/json_response.py +308 -0
  38. lets_plot/geo_data/gis/request.py +492 -0
  39. lets_plot/geo_data/gis/response.py +247 -0
  40. lets_plot/geo_data/livemap_helper.py +65 -0
  41. lets_plot/geo_data/to_geo_data_frame.py +141 -0
  42. lets_plot/geo_data/type_assertion.py +34 -0
  43. lets_plot/geo_data_internals/__init__.py +4 -0
  44. lets_plot/geo_data_internals/constants.py +13 -0
  45. lets_plot/geo_data_internals/utils.py +33 -0
  46. lets_plot/mapping.py +115 -0
  47. lets_plot/package_data/lets-plot.min.js +2 -0
  48. lets_plot/plot/__init__.py +62 -0
  49. lets_plot/plot/_global_theme.py +14 -0
  50. lets_plot/plot/annotation.py +233 -0
  51. lets_plot/plot/coord.py +242 -0
  52. lets_plot/plot/core.py +943 -0
  53. lets_plot/plot/expand_limits_.py +78 -0
  54. lets_plot/plot/facet.py +206 -0
  55. lets_plot/plot/font_features.py +71 -0
  56. lets_plot/plot/geom.py +7897 -0
  57. lets_plot/plot/geom_extras.py +53 -0
  58. lets_plot/plot/geom_function_.py +216 -0
  59. lets_plot/plot/geom_imshow_.py +401 -0
  60. lets_plot/plot/geom_livemap_.py +330 -0
  61. lets_plot/plot/gggrid_.py +141 -0
  62. lets_plot/plot/ggtb_.py +56 -0
  63. lets_plot/plot/guide.py +229 -0
  64. lets_plot/plot/label.py +187 -0
  65. lets_plot/plot/marginal_layer.py +181 -0
  66. lets_plot/plot/plot.py +237 -0
  67. lets_plot/plot/pos.py +344 -0
  68. lets_plot/plot/sampling.py +338 -0
  69. lets_plot/plot/sandbox_.py +26 -0
  70. lets_plot/plot/scale.py +3552 -0
  71. lets_plot/plot/scale_colormap_mpl.py +297 -0
  72. lets_plot/plot/scale_convenience.py +155 -0
  73. lets_plot/plot/scale_identity_.py +658 -0
  74. lets_plot/plot/scale_position.py +1336 -0
  75. lets_plot/plot/series_meta.py +123 -0
  76. lets_plot/plot/stat.py +581 -0
  77. lets_plot/plot/subplots.py +322 -0
  78. lets_plot/plot/theme_.py +681 -0
  79. lets_plot/plot/theme_set.py +393 -0
  80. lets_plot/plot/tooltip.py +486 -0
  81. lets_plot/plot/util.py +226 -0
  82. lets_plot/settings_utils.py +244 -0
  83. lets_plot/tilesets.py +364 -0
  84. lets_plot-4.5.0.dist-info/LICENSE +21 -0
  85. lets_plot-4.5.0.dist-info/METADATA +186 -0
  86. lets_plot-4.5.0.dist-info/RECORD +89 -0
  87. lets_plot-4.5.0.dist-info/WHEEL +5 -0
  88. lets_plot-4.5.0.dist-info/top_level.txt +2 -0
  89. lets_plot_kotlin_bridge.cp313-win_amd64.pyd +0 -0
@@ -0,0 +1,3552 @@
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 FeatureSpec, FeatureSpecArray
6
+ from .util import as_boolean
7
+
8
+ #
9
+ # Scales
10
+ #
11
+
12
+ __all__ = ['scale_shape',
13
+ 'scale_manual', 'scale_color_manual', 'scale_fill_manual', 'scale_size_manual',
14
+ 'scale_shape_manual', 'scale_linetype_manual', 'scale_alpha_manual',
15
+ 'scale_continuous', 'scale_fill_continuous', 'scale_color_continuous',
16
+ 'scale_gradient', 'scale_fill_gradient', 'scale_color_gradient',
17
+ 'scale_gradient2', 'scale_fill_gradient2', 'scale_color_gradient2',
18
+ 'scale_gradientn', 'scale_fill_gradientn', 'scale_color_gradientn',
19
+ 'scale_hue', 'scale_fill_hue', 'scale_color_hue',
20
+ 'scale_discrete', 'scale_fill_discrete', 'scale_color_discrete',
21
+ 'scale_grey', 'scale_fill_grey', 'scale_color_grey',
22
+ 'scale_brewer', 'scale_fill_brewer', 'scale_color_brewer',
23
+ 'scale_viridis', 'scale_fill_viridis', 'scale_color_viridis',
24
+ 'scale_alpha', 'scale_size', 'scale_size_area', 'scale_linewidth', 'scale_stroke'
25
+ ]
26
+
27
+
28
+ def scale_shape(solid=True, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None):
29
+ """
30
+ Scale for shapes.
31
+
32
+ Parameters
33
+ ----------
34
+ solid : bool, default=True
35
+ Are the shapes solid (default) True, or hollow (False).
36
+ name : str
37
+ The name of the scale - used as the axis label or the legend title.
38
+ breaks : list or dict
39
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
40
+ labels : list of str or dict
41
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
42
+ lablim : int, default=None
43
+ The maximum label length (in characters) before trimming is applied.
44
+ limits : list
45
+ Continuous scale: a numeric vector of length two providing limits of the scale.
46
+ Discrete scale: a vector specifying the data range for the scale
47
+ and the default order of their display in guides.
48
+ na_value
49
+ Missing values will be replaced with this value.
50
+ guide
51
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
52
+ format : str
53
+ Define the format for labels on the scale. The syntax resembles Python's:
54
+
55
+ - '.2f' -> '12.45'
56
+ - 'Num {}' -> 'Num 12.456789'
57
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
58
+
59
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
60
+
61
+ Returns
62
+ -------
63
+ `FeatureSpec`
64
+ Scale specification.
65
+
66
+ Notes
67
+ -----
68
+ Scale for shapes. A continuous variable cannot be mapped to shape.
69
+
70
+ Examples
71
+ --------
72
+ .. jupyter-execute::
73
+ :linenos:
74
+ :emphasize-lines: 8
75
+
76
+ import numpy as np
77
+ from lets_plot import *
78
+ LetsPlot.setup_html()
79
+ x = np.arange(10)
80
+ c = np.where(x < 5, 'a', 'b')
81
+ ggplot({'x': x, 'y': x, 'c': c}, aes('x', 'y')) + \\
82
+ geom_point(aes(shape='c'), size=5) + \\
83
+ scale_shape(solid=False, name='shapes')
84
+
85
+ """
86
+ solid = as_boolean(solid, default=True)
87
+ return _scale('shape',
88
+ name=name,
89
+ breaks=breaks,
90
+ labels=labels,
91
+ lablim=lablim,
92
+ limits=limits,
93
+ expand=None,
94
+ na_value=na_value,
95
+ guide=guide,
96
+ trans=None,
97
+ format=format,
98
+ #
99
+ solid=solid)
100
+
101
+
102
+ #
103
+ # Manual Scales
104
+ #
105
+
106
+ def scale_manual(aesthetic, values, *,
107
+ name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None):
108
+ """
109
+ Create your own discrete scale for the specified aesthetics.
110
+
111
+ Parameters
112
+ ----------
113
+ aesthetic : str or list
114
+ The name(s) of the aesthetic(s) that this scale works with.
115
+ values : list of str or dict
116
+ A set of aesthetic values to map data values to.
117
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
118
+ If a dictionary, then the values will be matched based on the names.
119
+ name : str
120
+ The name of the scale - used as the axis label or the legend title.
121
+ If None, the default, the name of the scale
122
+ is taken from the first mapping used for that aesthetic.
123
+ breaks : list or dict
124
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
125
+ labels : list of str or dict
126
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
127
+ lablim : int, default=None
128
+ The maximum label length (in characters) before trimming is applied.
129
+ limits : list
130
+ Continuous scale: a numeric vector of length two providing limits of the scale.
131
+ Discrete scale: a vector specifying the data range for the scale
132
+ and the default order of their display in guides.
133
+ na_value
134
+ Missing values will be replaced with this value.
135
+ guide
136
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
137
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
138
+ specifying additional arguments. 'none' will hide the guide.
139
+ format : str
140
+ Define the format for labels on the scale. The syntax resembles Python's:
141
+
142
+ - '.2f' -> '12.45'
143
+ - 'Num {}' -> 'Num 12.456789'
144
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
145
+
146
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
147
+
148
+ Returns
149
+ -------
150
+ `FeatureSpec` or `FeatureSpecArray`
151
+ Scales specification.
152
+
153
+ Notes
154
+ -----
155
+ Create your own scales for the specified aesthetics.
156
+
157
+ Examples
158
+ --------
159
+ .. jupyter-execute::
160
+ :linenos:
161
+ :emphasize-lines: 6-7
162
+
163
+ from lets_plot import *
164
+ LetsPlot.setup_html()
165
+ x = list(range(9))
166
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
167
+ geom_point(aes(color='x', fill='x'), shape=21, size=5) + \\
168
+ scale_manual(aesthetic=['color', 'fill'], values=['red', 'green', 'blue'], name='color', \\
169
+ breaks=[2, 4, 7], labels=['red', 'green', 'blue'])
170
+
171
+ """
172
+
173
+ # 'values' - dict of limits or breaks as keys and values as values
174
+ if isinstance(values, dict):
175
+ if breaks is None and limits is None:
176
+ breaks = list(values.keys())
177
+ values = list(values.values())
178
+ else:
179
+ base_order = breaks if limits is None else limits
180
+ if isinstance(base_order, dict):
181
+ base_order = list(base_order.values())
182
+ new_values = [values[break_value] for break_value in base_order if break_value in values]
183
+ if new_values:
184
+ no_match_values = list(set(values.values()) - set(new_values)) # doesn't preserve order
185
+ values = new_values + no_match_values
186
+ else:
187
+ values = None
188
+
189
+ return _scale(aesthetic,
190
+ name=name,
191
+ breaks=breaks,
192
+ labels=labels,
193
+ lablim=lablim,
194
+ limits=limits,
195
+ expand=None,
196
+ na_value=na_value,
197
+ guide=guide,
198
+ trans=None,
199
+ format=format,
200
+ #
201
+ values=values)
202
+
203
+
204
+ def scale_color_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None,
205
+ format=None):
206
+ """
207
+ Create your own discrete scale for `color` aesthetic.
208
+
209
+ Parameters
210
+ ----------
211
+ values : list of str or dict
212
+ A set of aesthetic values to map data values to.
213
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
214
+ If a dictionary, then the values will be matched based on the names.
215
+ name : str
216
+ The name of the scale - used as the axis label or the legend title.
217
+ If None, the default, the name of the scale
218
+ is taken from the first mapping used for that aesthetic.
219
+ breaks : list or dict
220
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
221
+ labels : list of str or dict
222
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
223
+ lablim : int, default=None
224
+ The maximum label length (in characters) before trimming is applied.
225
+ limits : list
226
+ Continuous scale: a numeric vector of length two providing limits of the scale.
227
+ Discrete scale: a vector specifying the data range for the scale
228
+ and the default order of their display in guides.
229
+ na_value
230
+ Missing values will be replaced with this value.
231
+ guide
232
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
233
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
234
+ specifying additional arguments. 'none' will hide the guide.
235
+ format : str
236
+ Define the format for labels on the scale. The syntax resembles Python's:
237
+
238
+ - '.2f' -> '12.45'
239
+ - 'Num {}' -> 'Num 12.456789'
240
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
241
+
242
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
243
+
244
+ Returns
245
+ -------
246
+ `FeatureSpec`
247
+ Scale specification.
248
+
249
+ Notes
250
+ -----
251
+ Create your own color scale. Values are strings, encoding colors.
252
+
253
+ Examples
254
+ --------
255
+ .. jupyter-execute::
256
+ :linenos:
257
+ :emphasize-lines: 6-7
258
+
259
+ from lets_plot import *
260
+ LetsPlot.setup_html()
261
+ x = list(range(9))
262
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
263
+ geom_point(aes(color='x'), shape=1, size=5) + \\
264
+ scale_color_manual(values=['red', 'green', 'blue'], name='color', \\
265
+ breaks=[2, 4, 7], labels=['red', 'green', 'blue'])
266
+
267
+ """
268
+ return scale_manual('color',
269
+ values=values,
270
+ name=name,
271
+ breaks=breaks,
272
+ labels=labels,
273
+ lablim=lablim,
274
+ limits=limits,
275
+ na_value=na_value,
276
+ guide=guide,
277
+ format=format)
278
+
279
+
280
+ def scale_fill_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None):
281
+ """
282
+ Create your own discrete scale for `fill` aesthetic.
283
+
284
+ Parameters
285
+ ----------
286
+ values : list of str or dict
287
+ A set of aesthetic values to map data values to.
288
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
289
+ If a dictionary, then the values will be matched based on the names.
290
+ name : str
291
+ The name of the scale - used as the axis label or the legend title.
292
+ If None, the default, the name of the scale
293
+ is taken from the first mapping used for that aesthetic.
294
+ breaks : list or dict
295
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
296
+ labels : list of str or dict
297
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
298
+ lablim : int, default=None
299
+ The maximum label length (in characters) before trimming is applied.
300
+ limits : list
301
+ Continuous scale: a numeric vector of length two providing limits of the scale.
302
+ Discrete scale: a vector specifying the data range for the scale
303
+ and the default order of their display in guides.
304
+ na_value
305
+ Missing values will be replaced with this value.
306
+ guide
307
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
308
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
309
+ specifying additional arguments. 'none' will hide the guide.
310
+ format : str
311
+ Define the format for labels on the scale. The syntax resembles Python's:
312
+
313
+ - '.2f' -> '12.45'
314
+ - 'Num {}' -> 'Num 12.456789'
315
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
316
+
317
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
318
+
319
+ Returns
320
+ -------
321
+ `FeatureSpec`
322
+ Scale specification.
323
+
324
+ Notes
325
+ -----
326
+ Create your own color scale for `fill` aesthetic. Values are strings, encoding filling colors.
327
+
328
+ Examples
329
+ --------
330
+ .. jupyter-execute::
331
+ :linenos:
332
+ :emphasize-lines: 6-7
333
+
334
+ from lets_plot import *
335
+ LetsPlot.setup_html()
336
+ x = list(range(9))
337
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
338
+ geom_point(aes(fill='x'), shape=21, size=5, color='black') + \\
339
+ scale_fill_manual(values=['green', 'yellow', 'red'], name='color', \\
340
+ breaks=[2, 4, 7], labels=['green', 'yellow', 'red'])
341
+
342
+ """
343
+ return scale_manual('fill',
344
+ values=values,
345
+ name=name,
346
+ breaks=breaks,
347
+ labels=labels,
348
+ lablim=lablim,
349
+ limits=limits,
350
+ na_value=na_value,
351
+ guide=guide,
352
+ format=format)
353
+
354
+
355
+ def scale_size_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None):
356
+ """
357
+ Create your own discrete scale for `size` aesthetic.
358
+
359
+ Parameters
360
+ ----------
361
+ values : list of str or dict
362
+ A set of aesthetic values to map data values to.
363
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
364
+ If a dictionary, then the values will be matched based on the names.
365
+ name : str
366
+ The name of the scale - used as the axis label or the legend title.
367
+ If None, the default, the name of the scale
368
+ is taken from the first mapping used for that aesthetic.
369
+ breaks : list or dict
370
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
371
+ labels : list of str or dict
372
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
373
+ lablim : int, default=None
374
+ The maximum label length (in characters) before trimming is applied.
375
+ limits : list
376
+ Continuous scale: a numeric vector of length two providing limits of the scale.
377
+ Discrete scale: a vector specifying the data range for the scale
378
+ and the default order of their display in guides.
379
+ na_value
380
+ Missing values will be replaced with this value.
381
+ guide
382
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
383
+ format : str
384
+ Define the format for labels on the scale. The syntax resembles Python's:
385
+
386
+ - '.2f' -> '12.45'
387
+ - 'Num {}' -> 'Num 12.456789'
388
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
389
+
390
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
391
+
392
+ Returns
393
+ -------
394
+ `FeatureSpec`
395
+ Scale specification.
396
+
397
+ Notes
398
+ -----
399
+ Create your own discrete scale for `size` aesthetic. Values are numbers, defining sizes.
400
+
401
+ Examples
402
+ --------
403
+ .. jupyter-execute::
404
+ :linenos:
405
+ :emphasize-lines: 8
406
+
407
+ import numpy as np
408
+ from lets_plot import *
409
+ LetsPlot.setup_html()
410
+ x = np.arange(10)
411
+ c = np.where(x < 5, 'a', 'b')
412
+ ggplot({'x': x, 'y': x, 'c': c}, aes('x', 'y')) + \\
413
+ geom_point(aes(size='c'), shape=1) + \\
414
+ scale_size_manual(name='size', values=[5, 8])
415
+
416
+ """
417
+ return scale_manual('size',
418
+ values=values,
419
+ name=name,
420
+ breaks=breaks,
421
+ labels=labels,
422
+ lablim=lablim,
423
+ limits=limits,
424
+ na_value=na_value,
425
+ guide=guide,
426
+ format=format)
427
+
428
+
429
+ def scale_shape_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None,
430
+ format=None):
431
+ """
432
+ Create your own discrete scale for `shape` aesthetic.
433
+
434
+ Parameters
435
+ ----------
436
+ values : list of str or dict
437
+ A set of aesthetic values to map data values to.
438
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
439
+ If a dictionary, then the values will be matched based on the names.
440
+ name : str
441
+ The name of the scale - used as the axis label or the legend title.
442
+ If None, the default, the name of the scale
443
+ is taken from the first mapping used for that aesthetic.
444
+ breaks : list or dict
445
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
446
+ labels : list of str or dict
447
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
448
+ lablim : int, default=None
449
+ The maximum label length (in characters) before trimming is applied.
450
+ limits : list
451
+ Continuous scale: a numeric vector of length two providing limits of the scale.
452
+ Discrete scale: a vector specifying the data range for the scale
453
+ and the default order of their display in guides.
454
+ na_value
455
+ Missing values will be replaced with this value.
456
+ guide
457
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
458
+ format : str
459
+ Define the format for labels on the scale. The syntax resembles Python's:
460
+
461
+ - '.2f' -> '12.45'
462
+ - 'Num {}' -> 'Num 12.456789'
463
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
464
+
465
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
466
+
467
+ Returns
468
+ -------
469
+ `FeatureSpec`
470
+ Scale specification.
471
+
472
+ Notes
473
+ -----
474
+ Create your own discrete scale for `size` aesthetic. Values are numbers, encoding shapes.
475
+
476
+ Examples
477
+ --------
478
+ .. jupyter-execute::
479
+ :linenos:
480
+ :emphasize-lines: 8
481
+
482
+ import numpy as np
483
+ from lets_plot import *
484
+ LetsPlot.setup_html()
485
+ x = np.arange(10)
486
+ c = np.where(x < 5, 'a', 'b')
487
+ ggplot({'x': x, 'y': x, 'c': c}, aes('x', 'y')) + \\
488
+ geom_point(aes(shape='c'), size=5) + \\
489
+ scale_shape_manual(values=[12, 13], name='shapes', labels=['12', '13'])
490
+
491
+ """
492
+ return scale_manual('shape',
493
+ values=values,
494
+ name=name,
495
+ breaks=breaks,
496
+ labels=labels,
497
+ lablim=lablim,
498
+ limits=limits,
499
+ na_value=na_value,
500
+ guide=guide,
501
+ format=format)
502
+
503
+
504
+ def scale_linetype_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None,
505
+ format=None):
506
+ """
507
+ Create your own discrete scale for line type aesthetic.
508
+
509
+ Parameters
510
+ ----------
511
+ values : list of str or dict
512
+ A set of aesthetic values to map data values to.
513
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
514
+ If a dictionary, then the values will be matched based on the names.
515
+ name : str
516
+ The name of the scale - used as the axis label or the legend title.
517
+ If None, the default, the name of the scale
518
+ is taken from the first mapping used for that aesthetic.
519
+ breaks : list or dict
520
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
521
+ labels : list of str or dict
522
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
523
+ lablim : int, default=None
524
+ The maximum label length (in characters) before trimming is applied.
525
+ limits : list
526
+ Continuous scale: a numeric vector of length two providing limits of the scale.
527
+ Discrete scale: a vector specifying the data range for the scale
528
+ and the default order of their display in guides.
529
+ na_value
530
+ Missing values will be replaced with this value.
531
+ guide
532
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
533
+ format : str
534
+ Define the format for labels on the scale. The syntax resembles Python's:
535
+
536
+ - '.2f' -> '12.45'
537
+ - 'Num {}' -> 'Num 12.456789'
538
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
539
+
540
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
541
+
542
+ Returns
543
+ -------
544
+ `FeatureSpec`
545
+ Scale specification.
546
+
547
+ Notes
548
+ -----
549
+ Create your own discrete scale for line type aesthetic.
550
+ Values are strings or numbers, encoding linetypes.
551
+ Available codes and names: 0 = 'blank', 1 = 'solid', 2 = 'dashed', 3 = 'dotted', 4 = 'dotdash',
552
+ 5 = 'longdash', 6 = 'twodash'.
553
+
554
+ Examples
555
+ --------
556
+ .. jupyter-execute::
557
+ :linenos:
558
+ :emphasize-lines: 5-6
559
+
560
+ from lets_plot import *
561
+ LetsPlot.setup_html()
562
+ x = [-.3, -.1, .1, .3]
563
+ ggplot() + geom_hline(aes(yintercept=x, linetype=x), size=1) + \\
564
+ scale_linetype_manual(values=[3, 4, 5, 6], breaks=[-0.3, -0.1, 0.1, 0.3],
565
+ labels=['dotted', 'dotdash', 'longdash', 'twodash'])
566
+
567
+ """
568
+ return scale_manual('linetype',
569
+ values=values,
570
+ name=name,
571
+ breaks=breaks,
572
+ labels=labels,
573
+ lablim=lablim,
574
+ limits=limits,
575
+ na_value=na_value,
576
+ guide=guide,
577
+ format=format)
578
+
579
+
580
+ def scale_alpha_manual(values, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None,
581
+ format=None):
582
+ """
583
+ Create your own discrete scale for `alpha` (transparency) aesthetic.
584
+
585
+ Parameters
586
+ ----------
587
+ values : list of str or dict
588
+ A set of aesthetic values to map data values to.
589
+ If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
590
+ If a dictionary, then the values will be matched based on the names.
591
+ name : str
592
+ The name of the scale - used as the axis label or the legend title.
593
+ If None, the default, the name of the scale
594
+ is taken from the first mapping used for that aesthetic.
595
+ breaks : list or dict
596
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
597
+ labels : list of str or dict
598
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
599
+ lablim : int, default=None
600
+ The maximum label length (in characters) before trimming is applied.
601
+ limits : list
602
+ Continuous scale: a numeric vector of length two providing limits of the scale.
603
+ Discrete scale: a vector specifying the data range for the scale
604
+ and the default order of their display in guides.
605
+ na_value
606
+ Missing values will be replaced with this value.
607
+ guide
608
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
609
+ format : str
610
+ Define the format for labels on the scale. The syntax resembles Python's:
611
+
612
+ - '.2f' -> '12.45'
613
+ - 'Num {}' -> 'Num 12.456789'
614
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
615
+
616
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
617
+
618
+ Returns
619
+ -------
620
+ `FeatureSpec`
621
+ Scale specification.
622
+
623
+ Notes
624
+ -----
625
+ Create your own discrete scale for `alpha` (transparency) aesthetic.
626
+ Accept values between 0 and 1.
627
+
628
+ Examples
629
+ --------
630
+ .. jupyter-execute::
631
+ :linenos:
632
+ :emphasize-lines: 6
633
+
634
+ from lets_plot import *
635
+ LetsPlot.setup_html()
636
+ x = list(range(10))
637
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
638
+ geom_point(aes(alpha='x'), shape=21, size=5) + \\
639
+ scale_alpha_manual(values=[.2, .5, .9])
640
+
641
+ """
642
+ return scale_manual('alpha',
643
+ values=values,
644
+ name=name,
645
+ breaks=breaks,
646
+ labels=labels,
647
+ lablim=lablim,
648
+ limits=limits,
649
+ na_value=na_value,
650
+ guide=guide,
651
+ format=format)
652
+
653
+
654
+ def _is_color_scale(aesthetic):
655
+ color_aesthetics = ['color', 'fill', 'paint_a', 'paint_b', 'paint_c']
656
+ if isinstance(aesthetic, str):
657
+ is_color_scale = aesthetic in color_aesthetics
658
+ elif isinstance(aesthetic, list):
659
+ is_color_scale = set(aesthetic).issubset(color_aesthetics)
660
+ else:
661
+ is_color_scale = False
662
+ return is_color_scale
663
+
664
+
665
+ #
666
+ # Scale for continuous data
667
+ #
668
+
669
+ def scale_continuous(aesthetic, *,
670
+ name=None, breaks=None, labels=None, lablim=None,
671
+ limits=None, na_value=None, guide=None, trans=None, format=None,
672
+ scale_mapper_kind=None,
673
+ **kwargs):
674
+ """
675
+ General purpose scale for continuous data.
676
+ Use it to adjust most common properties of a default scale for given aesthetics.
677
+
678
+ Parameters
679
+ ----------
680
+ aesthetic : str or list
681
+ The name(s) of the aesthetic(s) that this scale works with.
682
+ name : str
683
+ The name of the scale - used as the axis label or the legend title.
684
+ If None, the default, the name of the scale
685
+ is taken from the first mapping used for that aesthetic.
686
+ breaks : list or dict
687
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
688
+ labels : list of str or dict
689
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
690
+ lablim : int, default=None
691
+ The maximum label length (in characters) before trimming is applied.
692
+ limits : list
693
+ A numeric vector of length two providing limits of the scale.
694
+ na_value
695
+ Missing values will be replaced with this value.
696
+ guide
697
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
698
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
699
+ specifying additional arguments. 'none' will hide the guide.
700
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
701
+ Name of built-in transformation.
702
+ format : str
703
+ Define the format for labels on the scale. The syntax resembles Python's:
704
+
705
+ - '.2f' -> '12.45'
706
+ - 'Num {}' -> 'Num 12.456789'
707
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
708
+
709
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
710
+ scale_mapper_kind : {'identity', 'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap', 'size_area'}
711
+ The type of the scale.
712
+ If None (the default) and the scale is color, then 'color_gradient' will be used.
713
+ kwargs :
714
+ Additional parameters for the specified scale type.
715
+
716
+ Returns
717
+ -------
718
+ `FeatureSpec` or `FeatureSpecArray`
719
+ Scales specification.
720
+
721
+ Notes
722
+ -----
723
+ Define most common properties of a continuous scale for the specified aesthetics.
724
+
725
+ Examples
726
+ --------
727
+ .. jupyter-execute::
728
+ :linenos:
729
+ :emphasize-lines: 6
730
+
731
+ from lets_plot import *
732
+ LetsPlot.setup_html()
733
+ x = list(range(50))
734
+ ggplot({'x': x}, aes(x='x')) + \\
735
+ geom_tile(aes(color='x', fill='x')) + \\
736
+ scale_continuous(aesthetic=['color', 'fill'], breaks=[5, 25, 45]) + \\
737
+ coord_cartesian() + \\
738
+ ggsize(600, 200)
739
+
740
+ """
741
+ if _is_color_scale(aesthetic):
742
+ scale_mapper_kind = 'color_gradient' if scale_mapper_kind is None else scale_mapper_kind
743
+
744
+ return _scale(aesthetic,
745
+ name=name,
746
+ breaks=breaks,
747
+ labels=labels,
748
+ lablim=lablim,
749
+ limits=limits,
750
+ expand=None,
751
+ na_value=na_value,
752
+ guide=guide,
753
+ trans=trans,
754
+ format=format,
755
+ #
756
+ scale_mapper_kind=scale_mapper_kind,
757
+ **kwargs)
758
+
759
+
760
+ def scale_fill_continuous(name=None, breaks=None, labels=None, lablim=None,
761
+ limits=None, na_value=None, guide=None, trans=None, format=None,
762
+ scale_mapper_kind=None,
763
+ **kwargs):
764
+ """
765
+ Color scale for `fill` aesthetic and continuous data.
766
+
767
+ Parameters
768
+ ----------
769
+ name : str
770
+ The name of the scale - used as the axis label or the legend title.
771
+ If None, the default, the name of the scale
772
+ is taken from the first mapping used for that aesthetic.
773
+ breaks : list or dict
774
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
775
+ labels : list of str or dict
776
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
777
+ lablim : int, default=None
778
+ The maximum label length (in characters) before trimming is applied.
779
+ limits : list
780
+ A numeric vector of length two providing limits of the scale.
781
+ na_value
782
+ Missing values will be replaced with this value.
783
+ guide
784
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
785
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
786
+ specifying additional arguments. 'none' will hide the guide.
787
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
788
+ Name of built-in transformation.
789
+ format : str
790
+ Define the format for labels on the scale. The syntax resembles Python's:
791
+
792
+ - '.2f' -> '12.45'
793
+ - 'Num {}' -> 'Num 12.456789'
794
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
795
+
796
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
797
+ scale_mapper_kind : {'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap'}
798
+ The type of color scale.
799
+ If None (the default), then 'color_gradient' will be used.
800
+ kwargs :
801
+ Additional parameters for the specified scale type.
802
+
803
+ Returns
804
+ -------
805
+ `FeatureSpec`
806
+ Scale specification.
807
+
808
+
809
+ Examples
810
+ --------
811
+ .. jupyter-execute::
812
+ :linenos:
813
+ :emphasize-lines: 6
814
+
815
+ from lets_plot import *
816
+ LetsPlot.setup_html()
817
+ x = list(range(50))
818
+ ggplot({'x': x}, aes(x='x')) + \\
819
+ geom_tile(aes(fill='x')) + \\
820
+ scale_fill_continuous(low='#1a9641', high='#d7191c') + \\
821
+ coord_cartesian() + \\
822
+ ggsize(600, 200)
823
+
824
+ """
825
+ return scale_continuous('fill',
826
+ name=name,
827
+ breaks=breaks,
828
+ labels=labels,
829
+ lablim=lablim,
830
+ limits=limits,
831
+ na_value=na_value,
832
+ guide=guide,
833
+ trans=trans,
834
+ format=format,
835
+ scale_mapper_kind=scale_mapper_kind,
836
+ **kwargs)
837
+
838
+
839
+ def scale_color_continuous(name=None, breaks=None, labels=None, lablim=None, limits=None,
840
+ na_value=None, guide=None, trans=None, format=None,
841
+ scale_mapper_kind=None,
842
+ **kwargs):
843
+ """
844
+ Color scale for `color` aesthetic and continuous data.
845
+
846
+ Parameters
847
+ ----------
848
+ name : str
849
+ The name of the scale - used as the axis label or the legend title.
850
+ If None, the default, the name of the scale
851
+ is taken from the first mapping used for that aesthetic.
852
+ breaks : list or dict
853
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
854
+ labels : list of str or dict
855
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
856
+ lablim : int, default=None
857
+ The maximum label length (in characters) before trimming is applied.
858
+ limits : list
859
+ A numeric vector of length two providing limits of the scale.
860
+ na_value
861
+ Missing values will be replaced with this value.
862
+ guide
863
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
864
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
865
+ specifying additional arguments. 'none' will hide the guide.
866
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
867
+ Name of built-in transformation.
868
+ format : str
869
+ Define the format for labels on the scale. The syntax resembles Python's:
870
+
871
+ - '.2f' -> '12.45'
872
+ - 'Num {}' -> 'Num 12.456789'
873
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
874
+
875
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
876
+ scale_mapper_kind : {'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap'}
877
+ The type of color scale.
878
+ If None (the default), then 'color_gradient' will be used.
879
+ kwargs :
880
+ Additional parameters for the specified scale type.
881
+
882
+ Returns
883
+ -------
884
+ `FeatureSpec`
885
+ Scale specification.
886
+
887
+ Examples
888
+ --------
889
+ .. jupyter-execute::
890
+ :linenos:
891
+ :emphasize-lines: 6
892
+
893
+ from lets_plot import *
894
+ LetsPlot.setup_html()
895
+ x = list(range(10))
896
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
897
+ geom_point(aes(color='x'), shape=1, size=5) + \\
898
+ scale_color_continuous(low='#1a9641', high='#d7191c')
899
+
900
+ """
901
+ return scale_continuous('color',
902
+ name=name,
903
+ breaks=breaks,
904
+ labels=labels,
905
+ lablim=lablim,
906
+ limits=limits,
907
+ na_value=na_value,
908
+ guide=guide,
909
+ trans=trans,
910
+ format=format,
911
+ scale_mapper_kind=scale_mapper_kind,
912
+ **kwargs)
913
+
914
+
915
+ #
916
+ # Gradient Color Scales
917
+ #
918
+
919
+ def scale_gradient(aesthetic, *,
920
+ low=None, high=None, name=None, breaks=None, labels=None, lablim=None,
921
+ limits=None, na_value=None, guide=None, trans=None, format=None):
922
+ """
923
+ Define smooth color gradient between two colors for the specified aesthetics.
924
+
925
+ Parameters
926
+ ----------
927
+ aesthetic : str or list
928
+ The name(s) of the aesthetic(s) that this scale works with.
929
+ low : str
930
+ Color for low end of gradient.
931
+ high : str
932
+ Color for high end of gradient.
933
+ name : str
934
+ The name of the scale - used as the axis label or the legend title.
935
+ If None, the default, the name of the scale
936
+ is taken from the first mapping used for that aesthetic.
937
+ breaks : list or dict
938
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
939
+ labels : list of str or dict
940
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
941
+ lablim : int, default=None
942
+ The maximum label length (in characters) before trimming is applied.
943
+ limits : list
944
+ Continuous scale: a numeric vector of length two providing limits of the scale.
945
+ Discrete scale: a vector specifying the data range for the scale
946
+ and the default order of their display in guides.
947
+ na_value
948
+ Missing values will be replaced with this value.
949
+ guide
950
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
951
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
952
+ specifying additional arguments. 'none' will hide the guide.
953
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
954
+ Name of built-in transformation.
955
+ format : str
956
+ Define the format for labels on the scale. The syntax resembles Python's:
957
+
958
+ - '.2f' -> '12.45'
959
+ - 'Num {}' -> 'Num 12.456789'
960
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
961
+
962
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
963
+
964
+ Returns
965
+ -------
966
+ `FeatureSpec` or `FeatureSpecArray`
967
+ Scales specification.
968
+
969
+ Notes
970
+ -----
971
+ Define smooth gradient between two colors (defined by low and high) for the specified aesthetics.
972
+
973
+ Examples
974
+ --------
975
+ .. jupyter-execute::
976
+ :linenos:
977
+ :emphasize-lines: 6
978
+
979
+ from lets_plot import *
980
+ LetsPlot.setup_html()
981
+ x = list(range(50))
982
+ ggplot({'x': x}, aes(x='x')) + \\
983
+ geom_tile(aes(color='x', fill='x')) + \\
984
+ scale_gradient(aesthetic=['color', 'fill'], low='#1a9641', high='#d7191c') + \\
985
+ coord_cartesian() + \\
986
+ ggsize(600, 200)
987
+
988
+ """
989
+ return _scale(aesthetic,
990
+ name=name,
991
+ breaks=breaks,
992
+ labels=labels,
993
+ lablim=lablim,
994
+ limits=limits,
995
+ expand=None,
996
+ na_value=na_value,
997
+ guide=guide,
998
+ trans=trans,
999
+ format=format,
1000
+ #
1001
+ low=low, high=high,
1002
+ scale_mapper_kind='color_gradient')
1003
+
1004
+
1005
+ def scale_fill_gradient(low=None, high=None, name=None, breaks=None, labels=None, lablim=None,
1006
+ limits=None, na_value=None, guide=None, trans=None, format=None):
1007
+ """
1008
+ Define smooth color gradient between two colors for `fill` aesthetic.
1009
+
1010
+ Parameters
1011
+ ----------
1012
+ low : str
1013
+ Color for low end of gradient.
1014
+ high : str
1015
+ Color for high end of gradient.
1016
+ name : str
1017
+ The name of the scale - used as the axis label or the legend title.
1018
+ If None, the default, the name of the scale
1019
+ is taken from the first mapping used for that aesthetic.
1020
+ breaks : list or dict
1021
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1022
+ labels : list of str or dict
1023
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1024
+ lablim : int, default=None
1025
+ The maximum label length (in characters) before trimming is applied.
1026
+ limits : list
1027
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1028
+ Discrete scale: a vector specifying the data range for the scale
1029
+ and the default order of their display in guides.
1030
+ na_value
1031
+ Missing values will be replaced with this value.
1032
+ guide
1033
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1034
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1035
+ specifying additional arguments. 'none' will hide the guide.
1036
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1037
+ Name of built-in transformation.
1038
+ format : str
1039
+ Define the format for labels on the scale. The syntax resembles Python's:
1040
+
1041
+ - '.2f' -> '12.45'
1042
+ - 'Num {}' -> 'Num 12.456789'
1043
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1044
+
1045
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1046
+
1047
+ Returns
1048
+ -------
1049
+ `FeatureSpec`
1050
+ Scale specification.
1051
+
1052
+ Notes
1053
+ -----
1054
+ Define smooth gradient between two colors (defined by low and high) for `fill` aesthetic.
1055
+
1056
+ Examples
1057
+ --------
1058
+ .. jupyter-execute::
1059
+ :linenos:
1060
+ :emphasize-lines: 6
1061
+
1062
+ from lets_plot import *
1063
+ LetsPlot.setup_html()
1064
+ x = list(range(50))
1065
+ ggplot({'x': x}, aes(x='x')) + \\
1066
+ geom_tile(aes(fill='x')) + \\
1067
+ scale_fill_gradient(low='#1a9641', high='#d7191c') + \\
1068
+ coord_cartesian() + \\
1069
+ ggsize(600, 200)
1070
+
1071
+ """
1072
+ return scale_gradient('fill',
1073
+ low=low, high=high,
1074
+ name=name,
1075
+ breaks=breaks,
1076
+ labels=labels,
1077
+ lablim=lablim,
1078
+ limits=limits,
1079
+ na_value=na_value,
1080
+ guide=guide,
1081
+ trans=trans,
1082
+ format=format)
1083
+
1084
+
1085
+ def scale_color_gradient(low=None, high=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
1086
+ na_value=None, guide=None, trans=None, format=None):
1087
+ """
1088
+ Define smooth color gradient between two colors for `color` aesthetic.
1089
+
1090
+ Parameters
1091
+ ----------
1092
+ low : str
1093
+ Color for low end of gradient.
1094
+ high : str
1095
+ Color for high end of gradient.
1096
+ name : str
1097
+ The name of the scale - used as the axis label or the legend title.
1098
+ If None, the default, the name of the scale
1099
+ is taken from the first mapping used for that aesthetic.
1100
+ breaks : list or dict
1101
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1102
+ labels : list of str or dict
1103
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1104
+ lablim : int, default=None
1105
+ The maximum label length (in characters) before trimming is applied.
1106
+ limits : list
1107
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1108
+ Discrete scale: a vector specifying the data range for the scale
1109
+ and the default order of their display in guides.
1110
+ na_value
1111
+ Missing values will be replaced with this value.
1112
+ guide
1113
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1114
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1115
+ specifying additional arguments. 'none' will hide the guide.
1116
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1117
+ Name of built-in transformation.
1118
+ format : str
1119
+ Define the format for labels on the scale. The syntax resembles Python's:
1120
+
1121
+ - '.2f' -> '12.45'
1122
+ - 'Num {}' -> 'Num 12.456789'
1123
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1124
+
1125
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1126
+
1127
+ Returns
1128
+ -------
1129
+ `FeatureSpec`
1130
+ Scale specification.
1131
+
1132
+ Notes
1133
+ -----
1134
+ Define smooth gradient between two colors (defined by low and high) for `color` aesthetic.
1135
+
1136
+ Examples
1137
+ --------
1138
+ .. jupyter-execute::
1139
+ :linenos:
1140
+ :emphasize-lines: 6
1141
+
1142
+ from lets_plot import *
1143
+ LetsPlot.setup_html()
1144
+ x = list(range(50))
1145
+ ggplot({'x': x}, aes(x='x')) + \\
1146
+ geom_tile(aes(color='x'), fill='white', size=3) + \\
1147
+ scale_color_gradient(low='#1a9641', high='#d7191c', guide='legend') + \\
1148
+ coord_cartesian() + \\
1149
+ ggsize(600, 200)
1150
+
1151
+ """
1152
+ return scale_gradient('color',
1153
+ low=low, high=high,
1154
+ name=name,
1155
+ breaks=breaks,
1156
+ labels=labels,
1157
+ lablim=lablim,
1158
+ limits=limits,
1159
+ na_value=na_value,
1160
+ guide=guide,
1161
+ trans=trans,
1162
+ format=format)
1163
+
1164
+
1165
+ def scale_gradient2(aesthetic, *,
1166
+ low=None, mid=None, high=None, midpoint=0, name=None, breaks=None, labels=None, lablim=None, limits=None,
1167
+ na_value=None, guide=None, trans=None, format=None):
1168
+ """
1169
+ Define diverging color gradient for the specified aesthetics.
1170
+
1171
+ Parameters
1172
+ ----------
1173
+ aesthetic : str or list
1174
+ The name(s) of the aesthetic(s) that this scale works with.
1175
+ low : str
1176
+ Color for low end of gradient.
1177
+ mid : str
1178
+ Color for mid-point.
1179
+ high : str
1180
+ Color for high end of gradient.
1181
+ midpoint : float, default=0.0
1182
+ The midpoint (in data value) of the diverging scale.
1183
+ name : str
1184
+ The name of the scale - used as the axis label or the legend title.
1185
+ If None, the default, the name of the scale
1186
+ is taken from the first mapping used for that aesthetic.
1187
+ breaks : list or dict
1188
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1189
+ labels : list of str or dict
1190
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1191
+ lablim : int, default=None
1192
+ The maximum label length (in characters) before trimming is applied.
1193
+ limits : list
1194
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1195
+ Discrete scale: a vector specifying the data range for the scale
1196
+ and the default order of their display in guides.
1197
+ na_value
1198
+ Missing values will be replaced with this value.
1199
+ guide
1200
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1201
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1202
+ specifying additional arguments. 'none' will hide the guide.
1203
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1204
+ Name of built-in transformation.
1205
+ format : str
1206
+ Define the format for labels on the scale. The syntax resembles Python's:
1207
+
1208
+ - '.2f' -> '12.45'
1209
+ - 'Num {}' -> 'Num 12.456789'
1210
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1211
+
1212
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1213
+
1214
+ Returns
1215
+ -------
1216
+ `FeatureSpec` or `FeatureSpecArray`
1217
+ Scales specification.
1218
+
1219
+ Notes
1220
+ -----
1221
+ Define diverging color gradient for the specified aesthetics. Default mid point is set to white color.
1222
+
1223
+ Examples
1224
+ --------
1225
+ .. jupyter-execute::
1226
+ :linenos:
1227
+ :emphasize-lines: 6
1228
+
1229
+ from lets_plot import *
1230
+ LetsPlot.setup_html()
1231
+ x = list(range(-25, 26))
1232
+ ggplot({'x': x}, aes(x='x')) + \\
1233
+ geom_tile(aes(color='x', fill='x')) + \\
1234
+ scale_gradient2(aesthetic=['color', 'fill'], low='#2b83ba', mid='#ffffbf', high='#d7191c') + \\
1235
+ coord_cartesian() + \\
1236
+ ggsize(600, 200)
1237
+
1238
+ """
1239
+ return _scale(aesthetic,
1240
+ name=name,
1241
+ breaks=breaks,
1242
+ labels=labels,
1243
+ lablim=lablim,
1244
+ limits=limits,
1245
+ expand=None,
1246
+ na_value=na_value,
1247
+ guide=guide,
1248
+ trans=trans,
1249
+ format=format,
1250
+ #
1251
+ low=low, mid=mid, high=high,
1252
+ midpoint=midpoint,
1253
+ scale_mapper_kind='color_gradient2')
1254
+
1255
+
1256
+ def scale_fill_gradient2(low=None, mid=None, high=None, midpoint=0, name=None, breaks=None, labels=None, lablim=None, limits=None,
1257
+ na_value=None, guide=None, trans=None, format=None):
1258
+ """
1259
+ Define diverging color gradient for `fill` aesthetic.
1260
+
1261
+ Parameters
1262
+ ----------
1263
+ low : str
1264
+ Color for low end of gradient.
1265
+ mid : str
1266
+ Color for mid-point.
1267
+ high : str
1268
+ Color for high end of gradient.
1269
+ midpoint : float, default=0.0
1270
+ The midpoint (in data value) of the diverging scale.
1271
+ name : str
1272
+ The name of the scale - used as the axis label or the legend title.
1273
+ If None, the default, the name of the scale
1274
+ is taken from the first mapping used for that aesthetic.
1275
+ breaks : list or dict
1276
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1277
+ labels : list of str or dict
1278
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1279
+ lablim : int, default=None
1280
+ The maximum label length (in characters) before trimming is applied.
1281
+ limits : list
1282
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1283
+ Discrete scale: a vector specifying the data range for the scale
1284
+ and the default order of their display in guides.
1285
+ na_value
1286
+ Missing values will be replaced with this value.
1287
+ guide
1288
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1289
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1290
+ specifying additional arguments. 'none' will hide the guide.
1291
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1292
+ Name of built-in transformation.
1293
+ format : str
1294
+ Define the format for labels on the scale. The syntax resembles Python's:
1295
+
1296
+ - '.2f' -> '12.45'
1297
+ - 'Num {}' -> 'Num 12.456789'
1298
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1299
+
1300
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1301
+
1302
+ Returns
1303
+ -------
1304
+ `FeatureSpec`
1305
+ Scale specification.
1306
+
1307
+ Notes
1308
+ -----
1309
+ Define diverging color gradient for `fill` aesthetic. Default mid point is set to white color.
1310
+
1311
+ Examples
1312
+ --------
1313
+ .. jupyter-execute::
1314
+ :linenos:
1315
+ :emphasize-lines: 6
1316
+
1317
+ from lets_plot import *
1318
+ LetsPlot.setup_html()
1319
+ x = list(range(-25, 26))
1320
+ ggplot({'x': x}, aes(x='x')) + \\
1321
+ geom_tile(aes(fill='x')) + \\
1322
+ scale_fill_gradient2(low='#2b83ba', mid='#ffffbf', high='#d7191c') + \\
1323
+ coord_cartesian() + \\
1324
+ ggsize(600, 200)
1325
+
1326
+ """
1327
+ return scale_gradient2('fill',
1328
+ low=low, mid=mid, high=high,
1329
+ midpoint=midpoint,
1330
+ name=name,
1331
+ breaks=breaks,
1332
+ labels=labels,
1333
+ lablim=lablim,
1334
+ limits=limits,
1335
+ na_value=na_value,
1336
+ guide=guide,
1337
+ trans=trans,
1338
+ format=format)
1339
+
1340
+
1341
+ def scale_color_gradient2(low=None, mid=None, high=None, midpoint=0, name=None, breaks=None, labels=None, lablim=None,
1342
+ limits=None, na_value=None, guide=None, trans=None, format=None):
1343
+ """
1344
+ Define diverging color gradient for `color` aesthetic.
1345
+
1346
+ Parameters
1347
+ ----------
1348
+ low : str
1349
+ Color for low end of gradient.
1350
+ mid : str
1351
+ Color for mid-point.
1352
+ high : str
1353
+ Color for high end of gradient.
1354
+ midpoint : float, default=0.0
1355
+ The midpoint (in data value) of the diverging scale.
1356
+ name : str
1357
+ The name of the scale - used as the axis label or the legend title.
1358
+ If None, the default, the name of the scale
1359
+ is taken from the first mapping used for that aesthetic.
1360
+ breaks : list or dict
1361
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1362
+ labels : list of str or dict
1363
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1364
+ lablim : int, default=None
1365
+ The maximum label length (in characters) before trimming is applied.
1366
+ limits : list
1367
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1368
+ Discrete scale: a vector specifying the data range for the scale
1369
+ and the default order of their display in guides.
1370
+ na_value
1371
+ Missing values will be replaced with this value.
1372
+ guide
1373
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1374
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1375
+ specifying additional arguments. 'none' will hide the guide.
1376
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1377
+ Name of built-in transformation.
1378
+ format : str
1379
+ Define the format for labels on the scale. The syntax resembles Python's:
1380
+
1381
+ - '.2f' -> '12.45'
1382
+ - 'Num {}' -> 'Num 12.456789'
1383
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1384
+
1385
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1386
+
1387
+ Returns
1388
+ -------
1389
+ `FeatureSpec`
1390
+ Scale specification.
1391
+
1392
+ Notes
1393
+ -----
1394
+ Define diverging color gradient for `color` aesthetic. Default mid point is set to white color.
1395
+
1396
+ Examples
1397
+ --------
1398
+ .. jupyter-execute::
1399
+ :linenos:
1400
+ :emphasize-lines: 6
1401
+
1402
+ from lets_plot import *
1403
+ LetsPlot.setup_html()
1404
+ x = list(range(-25, 26))
1405
+ ggplot({'x': x}, aes(x='x')) + \\
1406
+ geom_tile(aes(color='x'), fill='white', size=3) + \\
1407
+ scale_color_gradient2(low='#2b83ba', mid='#ffffbf', high='#d7191c') + \\
1408
+ coord_cartesian() + \\
1409
+ ggsize(600, 200)
1410
+
1411
+ """
1412
+ return scale_gradient2('color',
1413
+ low=low, mid=mid, high=high,
1414
+ midpoint=midpoint,
1415
+ name=name,
1416
+ breaks=breaks,
1417
+ labels=labels,
1418
+ lablim=lablim,
1419
+ limits=limits,
1420
+ na_value=na_value,
1421
+ guide=guide,
1422
+ trans=trans,
1423
+ format=format)
1424
+
1425
+
1426
+ def scale_gradientn(aesthetic, *,
1427
+ colors=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
1428
+ na_value=None, guide=None, trans=None, format=None):
1429
+ """
1430
+ Define smooth color gradient between multiple colors for the specified aesthetics.
1431
+
1432
+ Parameters
1433
+ ----------
1434
+ aesthetic : str or list
1435
+ The name(s) of the aesthetic(s) that this scale works with.
1436
+ colors : list
1437
+ Gradient colors list.
1438
+ name : str
1439
+ The name of the scale - used as the axis label or the legend title.
1440
+ If None, the default, the name of the scale
1441
+ is taken from the first mapping used for that aesthetic.
1442
+ breaks : list or dict
1443
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1444
+ labels : list of str or dict
1445
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1446
+ limits : list
1447
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1448
+ Discrete scale: a vector specifying the data range for the scale
1449
+ and the default order of their display in guides.
1450
+ lablim : int, default=None
1451
+ The maximum label length (in characters) before trimming is applied.
1452
+ na_value
1453
+ Missing values will be replaced with this value.
1454
+ guide
1455
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1456
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1457
+ specifying additional arguments. 'none' will hide the guide.
1458
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1459
+ Name of built-in transformation.
1460
+ format : str
1461
+ Define the format for labels on the scale. The syntax resembles Python's:
1462
+
1463
+ - '.2f' -> '12.45'
1464
+ - 'Num {}' -> 'Num 12.456789'
1465
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1466
+
1467
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1468
+
1469
+ Returns
1470
+ -------
1471
+ `FeatureSpec` or `FeatureSpecArray`
1472
+ Scales specification.
1473
+
1474
+ Notes
1475
+ -----
1476
+ Define smooth color gradient between multiple colors for the specified aesthetics.
1477
+
1478
+ Examples
1479
+ --------
1480
+ .. jupyter-execute::
1481
+ :linenos:
1482
+ :emphasize-lines: 7
1483
+
1484
+ from lets_plot import *
1485
+ LetsPlot.setup_html()
1486
+ x = list(range(-25, 26))
1487
+ colors = ["#e41a1c", "#e41a1c", "#e41a1c", "#4daf4a", "#377eb8"]
1488
+ ggplot({'x': x}, aes(x='x')) + \\
1489
+ geom_tile(aes(color='x', fill='x'),size=3) + \\
1490
+ scale_gradientn(aesthetic=['color', 'fill'], colors=colors) + \\
1491
+ coord_cartesian() + \\
1492
+ ggsize(600, 200)
1493
+
1494
+ """
1495
+ return _scale(aesthetic,
1496
+ name=name,
1497
+ breaks=breaks,
1498
+ labels=labels,
1499
+ lablim=lablim,
1500
+ limits=limits,
1501
+ expand=None,
1502
+ na_value=na_value,
1503
+ guide=guide,
1504
+ trans=trans,
1505
+ format=format,
1506
+ #
1507
+ colors=colors,
1508
+ scale_mapper_kind='color_gradientn')
1509
+
1510
+
1511
+ def scale_color_gradientn(colors=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
1512
+ na_value=None, guide=None, trans=None, format=None):
1513
+ """
1514
+ Define smooth color gradient between multiple colors for `color` aesthetic.
1515
+
1516
+ Parameters
1517
+ ----------
1518
+ colors : list
1519
+ Gradient colors list.
1520
+ name : str
1521
+ The name of the scale - used as the axis label or the legend title.
1522
+ If None, the default, the name of the scale
1523
+ is taken from the first mapping used for that aesthetic.
1524
+ breaks : list or dict
1525
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1526
+ labels : list of str or dict
1527
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1528
+ lablim : int, default=None
1529
+ The maximum label length (in characters) before trimming is applied.
1530
+ limits : list
1531
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1532
+ Discrete scale: a vector specifying the data range for the scale
1533
+ and the default order of their display in guides.
1534
+ na_value
1535
+ Missing values will be replaced with this value.
1536
+ guide
1537
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1538
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1539
+ specifying additional arguments. 'none' will hide the guide.
1540
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1541
+ Name of built-in transformation.
1542
+ format : str
1543
+ Define the format for labels on the scale. The syntax resembles Python's:
1544
+
1545
+ - '.2f' -> '12.45'
1546
+ - 'Num {}' -> 'Num 12.456789'
1547
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1548
+
1549
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1550
+
1551
+ Returns
1552
+ -------
1553
+ `FeatureSpec`
1554
+ Scale specification.
1555
+
1556
+ Notes
1557
+ -----
1558
+ Define smooth color gradient between multiple colors for `color` aesthetic.
1559
+
1560
+ Examples
1561
+ --------
1562
+ .. jupyter-execute::
1563
+ :linenos:
1564
+ :emphasize-lines: 7
1565
+
1566
+ from lets_plot import *
1567
+ LetsPlot.setup_html()
1568
+ x = list(range(-25, 26))
1569
+ colors = ["#e41a1c", "#e41a1c", "#e41a1c", "#4daf4a", "#377eb8"]
1570
+ ggplot({'x': x}, aes(x='x')) + \\
1571
+ geom_tile(aes(color='x'), fill='white', size=3) + \\
1572
+ scale_color_gradientn(colors=colors) + \\
1573
+ coord_cartesian() + \\
1574
+ ggsize(600, 200)
1575
+
1576
+ """
1577
+ return scale_gradientn('color',
1578
+ colors=colors,
1579
+ name=name,
1580
+ breaks=breaks,
1581
+ labels=labels,
1582
+ lablim=lablim,
1583
+ limits=limits,
1584
+ na_value=na_value,
1585
+ guide=guide,
1586
+ trans=trans,
1587
+ format=format)
1588
+
1589
+
1590
+ def scale_fill_gradientn(colors=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
1591
+ na_value=None, guide=None, trans=None, format=None):
1592
+ """
1593
+ Define smooth color gradient between multiple colors for `fill` aesthetic.
1594
+
1595
+ Parameters
1596
+ ----------
1597
+ colors : list
1598
+ Gradient colors list.
1599
+ name : str
1600
+ The name of the scale - used as the axis label or the legend title.
1601
+ If None, the default, the name of the scale
1602
+ is taken from the first mapping used for that aesthetic.
1603
+ breaks : list or dict
1604
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1605
+ labels : list of str or dict
1606
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1607
+ lablim : int, default=None
1608
+ The maximum label length (in characters) before trimming is applied.
1609
+ limits : list
1610
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1611
+ Discrete scale: a vector specifying the data range for the scale
1612
+ and the default order of their display in guides.
1613
+ na_value
1614
+ Missing values will be replaced with this value.
1615
+ guide
1616
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1617
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1618
+ specifying additional arguments. 'none' will hide the guide.
1619
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1620
+ Name of built-in transformation.
1621
+ format : str
1622
+ Define the format for labels on the scale. The syntax resembles Python's:
1623
+
1624
+ - '.2f' -> '12.45'
1625
+ - 'Num {}' -> 'Num 12.456789'
1626
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1627
+
1628
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1629
+
1630
+ Returns
1631
+ -------
1632
+ `FeatureSpec`
1633
+ Scale specification.
1634
+
1635
+ Notes
1636
+ -----
1637
+ Define smooth color gradient between multiple colors for `fill` aesthetic.
1638
+
1639
+ Examples
1640
+ --------
1641
+ .. jupyter-execute::
1642
+ :linenos:
1643
+ :emphasize-lines: 7
1644
+
1645
+ from lets_plot import *
1646
+ LetsPlot.setup_html()
1647
+ x = list(range(-25, 26))
1648
+ colors = ["#e41a1c", "#e41a1c", "#e41a1c", "#4daf4a", "#377eb8"]
1649
+ ggplot({'x': x}, aes(x='x')) + \\
1650
+ geom_tile(aes(fill='x'), size=3) + \\
1651
+ scale_fill_gradientn(colors=colors) + \\
1652
+ coord_cartesian() + \\
1653
+ ggsize(600, 200)
1654
+
1655
+ """
1656
+ return scale_gradientn('fill',
1657
+ colors=colors,
1658
+ name=name,
1659
+ breaks=breaks,
1660
+ labels=labels,
1661
+ lablim=lablim,
1662
+ limits=limits,
1663
+ na_value=na_value,
1664
+ guide=guide,
1665
+ trans=trans,
1666
+ format=format)
1667
+
1668
+
1669
+ def scale_hue(aesthetic, *,
1670
+ h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, lablim=None,
1671
+ limits=None, na_value=None, guide=None, trans=None, format=None):
1672
+ """
1673
+ Qualitative color scale with evenly spaced hues for the specified aesthetics.
1674
+
1675
+ Parameters
1676
+ ----------
1677
+ aesthetic : str or list
1678
+ The name(s) of the aesthetic(s) that this scale works with.
1679
+ h : list
1680
+ Range of hues (two numerics), in [0, 360].
1681
+ c : int
1682
+ Chroma (intensity of color), maximum value varies depending on.
1683
+ l : int
1684
+ Luminance (lightness), in [0, 100].
1685
+ direction : {1, -1}, default=1
1686
+ Direction to travel around the color wheel, 1=clockwise, -1=counter-clockwise.
1687
+ name : str
1688
+ The name of the scale - used as the axis label or the legend title.
1689
+ If None, the default, the name of the scale
1690
+ is taken from the first mapping used for that aesthetic.
1691
+ breaks : list or dict
1692
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1693
+ labels : list of str or dict
1694
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1695
+ lablim : int, default=None
1696
+ The maximum label length (in characters) before trimming is applied.
1697
+ limits : list
1698
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1699
+ Discrete scale: a vector specifying the data range for the scale
1700
+ and the default order of their display in guides.
1701
+ na_value
1702
+ Missing values will be replaced with this value.
1703
+ guide
1704
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1705
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1706
+ specifying additional arguments. 'none' will hide the guide.
1707
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1708
+ Name of built-in transformation.
1709
+ format : str
1710
+ Define the format for labels on the scale. The syntax resembles Python's:
1711
+
1712
+ - '.2f' -> '12.45'
1713
+ - 'Num {}' -> 'Num 12.456789'
1714
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1715
+
1716
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1717
+
1718
+ Returns
1719
+ -------
1720
+ `FeatureSpec` or `FeatureSpecArray`
1721
+ Scales specification.
1722
+
1723
+ Notes
1724
+ -----
1725
+ Define qualitative color scale with evenly spaced hues for the specified aesthetics.
1726
+
1727
+ Examples
1728
+ --------
1729
+ .. jupyter-execute::
1730
+ :linenos:
1731
+ :emphasize-lines: 6
1732
+
1733
+ from lets_plot import *
1734
+ LetsPlot.setup_html()
1735
+ x = list(range(50))
1736
+ ggplot({'x': x}, aes(x='x')) + \\
1737
+ geom_tile(aes(color='x', fill='x'), fill='white', size=3) + \\
1738
+ scale_hue(aesthetic=['color', 'fill'], c=20, l=90) + \\
1739
+ coord_cartesian() + \\
1740
+ ggsize(600, 200)
1741
+
1742
+ """
1743
+ return _scale(aesthetic=aesthetic,
1744
+ name=name,
1745
+ breaks=breaks,
1746
+ labels=labels,
1747
+ lablim=lablim,
1748
+ limits=limits,
1749
+ expand=None,
1750
+ na_value=na_value,
1751
+ guide=guide,
1752
+ trans=trans,
1753
+ format=format,
1754
+ #
1755
+ h=h, c=c, l=l, h_start=h_start,
1756
+ direction=direction,
1757
+ scale_mapper_kind='color_hue')
1758
+
1759
+
1760
+ def scale_fill_hue(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, lablim=None,
1761
+ limits=None, na_value=None, guide=None, trans=None, format=None):
1762
+ """
1763
+ Qualitative color scale with evenly spaced hues for `fill` aesthetic.
1764
+
1765
+ Parameters
1766
+ ----------
1767
+ h : list, default=[15, 375]
1768
+ Range of hues (two numerics), in [0, 360].
1769
+ c : int, default=100
1770
+ Chroma (intensity of color), maximum value varies depending on.
1771
+ l : int, default=65
1772
+ Luminance (lightness), in [0, 100].
1773
+ h_start : int, default=0
1774
+ Hue starting point.
1775
+ direction : {1, -1}, default=1
1776
+ Direction to travel around the color wheel, 1=clockwise, -1=counter-clockwise.
1777
+ name : str
1778
+ The name of the scale - used as the axis label or the legend title.
1779
+ If None, the default, the name of the scale
1780
+ is taken from the first mapping used for that aesthetic.
1781
+ breaks : list or dict
1782
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1783
+ labels : list of str or dict
1784
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1785
+ lablim : int, default=None
1786
+ The maximum label length (in characters) before trimming is applied.
1787
+ limits : list
1788
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1789
+ Discrete scale: a vector specifying the data range for the scale
1790
+ and the default order of their display in guides.
1791
+ na_value
1792
+ Missing values will be replaced with this value.
1793
+ guide
1794
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1795
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1796
+ specifying additional arguments. 'none' will hide the guide.
1797
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1798
+ Name of built-in transformation.
1799
+ format : str
1800
+ Define the format for labels on the scale. The syntax resembles Python's:
1801
+
1802
+ - '.2f' -> '12.45'
1803
+ - 'Num {}' -> 'Num 12.456789'
1804
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1805
+
1806
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1807
+
1808
+ Returns
1809
+ -------
1810
+ `FeatureSpec`
1811
+ Scale specification.
1812
+
1813
+ Notes
1814
+ -----
1815
+ Define qualitative color scale with evenly spaced hues for `fill` aesthetic.
1816
+
1817
+ Examples
1818
+ --------
1819
+ .. jupyter-execute::
1820
+ :linenos:
1821
+ :emphasize-lines: 6
1822
+
1823
+ from lets_plot import *
1824
+ LetsPlot.setup_html()
1825
+ x = list(range(50))
1826
+ ggplot({'x': x}, aes(x='x')) + \\
1827
+ geom_tile(aes(fill='x')) + \\
1828
+ scale_fill_hue(c=85) + \\
1829
+ coord_cartesian() + \\
1830
+ ggsize(600, 200)
1831
+
1832
+ """
1833
+ return scale_hue('fill',
1834
+ h=h, c=c, l=l,
1835
+ h_start=h_start,
1836
+ direction=direction,
1837
+ name=name,
1838
+ breaks=breaks,
1839
+ labels=labels,
1840
+ lablim=lablim,
1841
+ limits=limits,
1842
+ na_value=na_value,
1843
+ guide=guide,
1844
+ trans=trans,
1845
+ format=format)
1846
+
1847
+
1848
+ def scale_color_hue(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, lablim=None,
1849
+ limits=None, na_value=None, guide=None, trans=None, format=None):
1850
+ """
1851
+ Qualitative color scale with evenly spaced hues for `color` aesthetic.
1852
+
1853
+ Parameters
1854
+ ----------
1855
+ h : list
1856
+ Range of hues (two numerics), in [0, 360].
1857
+ c : int
1858
+ Chroma (intensity of color), maximum value varies depending on.
1859
+ l : int
1860
+ Luminance (lightness), in [0, 100].
1861
+ direction : {1, -1}, default=1
1862
+ Direction to travel around the color wheel, 1=clockwise, -1=counter-clockwise.
1863
+ name : str
1864
+ The name of the scale - used as the axis label or the legend title.
1865
+ If None, the default, the name of the scale
1866
+ is taken from the first mapping used for that aesthetic.
1867
+ breaks : list or dict
1868
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1869
+ labels : list of str or dict
1870
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1871
+ lablim : int, default=None
1872
+ The maximum label length (in characters) before trimming is applied.
1873
+ limits : list
1874
+ Continuous scale: a numeric vector of length two providing limits of the scale.
1875
+ Discrete scale: a vector specifying the data range for the scale
1876
+ and the default order of their display in guides.
1877
+ na_value
1878
+ Missing values will be replaced with this value.
1879
+ guide
1880
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1881
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1882
+ specifying additional arguments. 'none' will hide the guide.
1883
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
1884
+ Name of built-in transformation.
1885
+ format : str
1886
+ Define the format for labels on the scale. The syntax resembles Python's:
1887
+
1888
+ - '.2f' -> '12.45'
1889
+ - 'Num {}' -> 'Num 12.456789'
1890
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1891
+
1892
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1893
+
1894
+ Returns
1895
+ -------
1896
+ `FeatureSpec`
1897
+ Scale specification.
1898
+
1899
+ Notes
1900
+ -----
1901
+ Define qualitative color scale with evenly spaced hues for `color` aesthetic.
1902
+
1903
+ Examples
1904
+ --------
1905
+ .. jupyter-execute::
1906
+ :linenos:
1907
+ :emphasize-lines: 6
1908
+
1909
+ from lets_plot import *
1910
+ LetsPlot.setup_html()
1911
+ x = list(range(50))
1912
+ ggplot({'x': x}, aes(x='x')) + \\
1913
+ geom_tile(aes(color='x'), fill='white', size=3) + \\
1914
+ scale_color_hue(c=20, l=90) + \\
1915
+ coord_cartesian() + \\
1916
+ ggsize(600, 200)
1917
+
1918
+ """
1919
+ return scale_hue('color',
1920
+ h=h, c=c, l=l,
1921
+ h_start=h_start,
1922
+ direction=direction,
1923
+ name=name,
1924
+ breaks=breaks,
1925
+ labels=labels,
1926
+ lablim=lablim,
1927
+ limits=limits,
1928
+ na_value=na_value,
1929
+ guide=guide,
1930
+ trans=trans,
1931
+ format=format)
1932
+
1933
+
1934
+ def scale_discrete(aesthetic, *,
1935
+ direction=None,
1936
+ name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None,
1937
+ scale_mapper_kind=None,
1938
+ **kwargs):
1939
+ """
1940
+ General purpose scale for discrete data.
1941
+ Use it to adjust most common properties of a default scale for given aesthetics.
1942
+
1943
+ Parameters
1944
+ ----------
1945
+ aesthetic : str or list
1946
+ The name(s) of the aesthetic(s) that this scale works with.
1947
+ direction : {1, -1}, default=1
1948
+ Set the order of colors in the scale. If 1, colors are as output by brewer palette.
1949
+ If -1, the order of colors is reversed.
1950
+ name : str
1951
+ The name of the scale - used as the axis label or the legend title.
1952
+ If None, the default, the name of the scale
1953
+ is taken from the first mapping used for that aesthetic.
1954
+ breaks : list or dict
1955
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
1956
+ labels : list of str or dict
1957
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
1958
+ lablim : int, default=None
1959
+ The maximum label length (in characters) before trimming is applied.
1960
+ limits : list
1961
+ A vector specifying the data range for the scale
1962
+ and the default order of their display in guides.
1963
+ na_value
1964
+ Missing values will be replaced with this value.
1965
+ guide
1966
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
1967
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
1968
+ specifying additional arguments. 'none' will hide the guide.
1969
+ format : str
1970
+ Define the format for labels on the scale. The syntax resembles Python's:
1971
+
1972
+ - '.2f' -> '12.45'
1973
+ - 'Num {}' -> 'Num 12.456789'
1974
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
1975
+
1976
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
1977
+ scale_mapper_kind : {'identity', 'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap', 'size_area'}
1978
+ The type of the scale.
1979
+ If None (the default) and the scale is color, then 'color_brewer' will be used.
1980
+ kwargs :
1981
+ Additional parameters for the specified scale type.
1982
+
1983
+ Returns
1984
+ -------
1985
+ `FeatureSpec` or `FeatureSpecArray`
1986
+ Scales specification.
1987
+
1988
+ Notes
1989
+ -----
1990
+ Define scale for discrete data to adjust properties for the specified aesthetics.
1991
+
1992
+ Examples
1993
+ --------
1994
+ .. jupyter-execute::
1995
+ :linenos:
1996
+ :emphasize-lines: 10
1997
+
1998
+ import numpy as np
1999
+ from lets_plot import *
2000
+ LetsPlot.setup_html()
2001
+ np.random.seed(100)
2002
+ n = 50
2003
+ x = np.random.rand(n)
2004
+ y = np.random.rand(n)
2005
+ z = np.random.rand(n)
2006
+ ggplot() + geom_point(aes(x, y, color=z, fill=z), shape=21, size=4) + \\
2007
+ scale_discrete(aesthetic=['color', 'fill'], guide='none')
2008
+
2009
+ """
2010
+ return _scale(aesthetic=aesthetic,
2011
+ name=name,
2012
+ breaks=breaks,
2013
+ labels=labels,
2014
+ lablim=lablim,
2015
+ limits=limits,
2016
+ expand=None,
2017
+ na_value=na_value,
2018
+ guide=guide,
2019
+ format=format,
2020
+ #
2021
+ direction=direction,
2022
+ discrete=True,
2023
+ scale_mapper_kind=scale_mapper_kind,
2024
+ **kwargs)
2025
+
2026
+
2027
+ def scale_fill_discrete(direction=None,
2028
+ name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None,
2029
+ scale_mapper_kind=None,
2030
+ **kwargs):
2031
+ """
2032
+ Color scale for `fill` aesthetic and discrete data.
2033
+
2034
+ Parameters
2035
+ ----------
2036
+ direction : {1, -1}, default=1
2037
+ Set the order of colors in the scale. If 1, colors are as output by original palette.
2038
+ If -1, the order of colors is reversed.
2039
+ name : str
2040
+ The name of the scale - used as the axis label or the legend title.
2041
+ If None, the default, the name of the scale
2042
+ is taken from the first mapping used for that aesthetic.
2043
+ breaks : list or dict
2044
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2045
+ labels : list of str or dict
2046
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2047
+ lablim : int, default=None
2048
+ The maximum label length (in characters) before trimming is applied.
2049
+ limits : list
2050
+ A vector specifying the data range for the scale
2051
+ and the default order of their display in guides.
2052
+ na_value
2053
+ Missing values will be replaced with this value.
2054
+ guide
2055
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2056
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2057
+ specifying additional arguments. 'none' will hide the guide.
2058
+ format : str
2059
+ Define the format for labels on the scale. The syntax resembles Python's:
2060
+
2061
+ - '.2f' -> '12.45'
2062
+ - 'Num {}' -> 'Num 12.456789'
2063
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2064
+
2065
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2066
+ scale_mapper_kind : {'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap'}
2067
+ The type of color scale.
2068
+ If None (the default), then 'color_brewer' will be used.
2069
+ kwargs :
2070
+ Additional parameters for the specified scale type.
2071
+
2072
+ Returns
2073
+ -------
2074
+ `FeatureSpec`
2075
+ Scale specification.
2076
+
2077
+ Examples
2078
+ --------
2079
+ .. jupyter-execute::
2080
+ :linenos:
2081
+ :emphasize-lines: 10
2082
+
2083
+ import numpy as np
2084
+ from lets_plot import *
2085
+ LetsPlot.setup_html()
2086
+ np.random.seed(100)
2087
+ n = 50
2088
+ x = np.random.rand(n)
2089
+ y = np.random.rand(n)
2090
+ z = np.random.rand(n)
2091
+ ggplot() + geom_point(aes(x, y, fill=z), shape=21, size=4, color='gray') + \\
2092
+ scale_fill_discrete(guide='none')
2093
+
2094
+ """
2095
+ return scale_discrete('fill',
2096
+ direction=direction,
2097
+ name=name,
2098
+ breaks=breaks,
2099
+ labels=labels,
2100
+ lablim=lablim,
2101
+ limits=limits,
2102
+ na_value=na_value,
2103
+ guide=guide,
2104
+ format=format,
2105
+ scale_mapper_kind=scale_mapper_kind,
2106
+ **kwargs)
2107
+
2108
+
2109
+ def scale_color_discrete(direction=None,
2110
+ name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None,
2111
+ scale_mapper_kind=None,
2112
+ **kwargs):
2113
+ """
2114
+ Color scale for `color` aesthetic and discrete data.
2115
+
2116
+ Parameters
2117
+ ----------
2118
+ direction : {1, -1}, default=1
2119
+ Set the order of colors in the scale. If 1, colors are as output by original palette.
2120
+ If -1, the order of colors is reversed.
2121
+ name : str
2122
+ The name of the scale - used as the axis label or the legend title.
2123
+ If None, the default, the name of the scale
2124
+ is taken from the first mapping used for that aesthetic.
2125
+ breaks : list or dict
2126
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2127
+ labels : list of str or dict
2128
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2129
+ lablim : int, default=None
2130
+ The maximum label length (in characters) before trimming is applied.
2131
+ limits : list
2132
+ A vector specifying the data range for the scale
2133
+ and the default order of their display in guides.
2134
+ na_value
2135
+ Missing values will be replaced with this value.
2136
+ guide
2137
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2138
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2139
+ specifying additional arguments. 'none' will hide the guide.
2140
+ format : str
2141
+ Define the format for labels on the scale. The syntax resembles Python's:
2142
+
2143
+ - '.2f' -> '12.45'
2144
+ - 'Num {}' -> 'Num 12.456789'
2145
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2146
+
2147
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2148
+ scale_mapper_kind : {'color_gradient', 'color_gradient2', 'color_gradientn', 'color_hue', 'color_grey', 'color_brewer', 'color_cmap'}
2149
+ The type of color scale.
2150
+ If None (the default), then 'color_brewer' will be used.
2151
+ kwargs:
2152
+ Additional parameters for the specified scale type.
2153
+
2154
+ Returns
2155
+ -------
2156
+ `FeatureSpec`
2157
+ Scale specification.
2158
+
2159
+ Examples
2160
+ --------
2161
+ .. jupyter-execute::
2162
+ :linenos:
2163
+ :emphasize-lines: 10
2164
+
2165
+ import numpy as np
2166
+ from lets_plot import *
2167
+ LetsPlot.setup_html()
2168
+ np.random.seed(100)
2169
+ n = 50
2170
+ x = np.random.rand(n)
2171
+ y = np.random.rand(n)
2172
+ z = np.random.rand(n)
2173
+ ggplot() + geom_point(aes(x, y, color=z), size=4) + \\
2174
+ scale_color_discrete(guide='none')
2175
+
2176
+ """
2177
+ return scale_discrete('color',
2178
+ direction=direction,
2179
+ name=name,
2180
+ breaks=breaks,
2181
+ labels=labels,
2182
+ lablim=lablim,
2183
+ limits=limits,
2184
+ na_value=na_value,
2185
+ guide=guide,
2186
+ format=format,
2187
+ scale_mapper_kind=scale_mapper_kind,
2188
+ **kwargs)
2189
+
2190
+
2191
+ def scale_grey(aesthetic, *,
2192
+ start=None, end=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2193
+ na_value=None, guide=None, trans=None, format=None):
2194
+ """
2195
+ Sequential grey color scale for the specified aesthetics.
2196
+
2197
+ Parameters
2198
+ ----------
2199
+ aesthetic : str or list
2200
+ The name(s) of the aesthetic(s) that this scale works with.
2201
+ start : float
2202
+ Gray value at low end of palette in range [0, 1].
2203
+ end : float
2204
+ Gray value at high end of palette in range [0, 1].
2205
+ name : str
2206
+ The name of the scale - used as the axis label or the legend title.
2207
+ If None, the default, the name of the scale
2208
+ is taken from the first mapping used for that aesthetic.
2209
+ breaks : list or dict
2210
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2211
+ labels : list of str or dict
2212
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2213
+ lablim : int, default=None
2214
+ The maximum label length (in characters) before trimming is applied.
2215
+ limits : list
2216
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2217
+ Discrete scale: a vector specifying the data range for the scale
2218
+ and the default order of their display in guides.
2219
+ na_value
2220
+ Missing values will be replaced with this value.
2221
+ guide
2222
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2223
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2224
+ specifying additional arguments. 'none' will hide the guide.
2225
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2226
+ Name of built-in transformation.
2227
+ format : str
2228
+ Define the format for labels on the scale. The syntax resembles Python's:
2229
+
2230
+ - '.2f' -> '12.45'
2231
+ - 'Num {}' -> 'Num 12.456789'
2232
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2233
+
2234
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2235
+
2236
+ Returns
2237
+ -------
2238
+ `FeatureSpec` or `FeatureSpecArray`
2239
+ Scales specification.
2240
+
2241
+ Notes
2242
+ -----
2243
+ Define sequential grey color scale for the specified aesthetics.
2244
+
2245
+ Examples
2246
+ --------
2247
+ .. jupyter-execute::
2248
+ :linenos:
2249
+ :emphasize-lines: 6
2250
+
2251
+ from lets_plot import *
2252
+ LetsPlot.setup_html()
2253
+ x = list(range(50))
2254
+ ggplot({'x': x}, aes(x='x')) + \\
2255
+ geom_tile(aes(color='x', fill='x')) + \\
2256
+ scale_grey(aesthetic=['color', 'fill'], start=.9, end=.1) + \\
2257
+ coord_cartesian() + \\
2258
+ ggsize(600, 200)
2259
+
2260
+ """
2261
+ start, end = _greyscale_check_parameters(start, end)
2262
+
2263
+ return _scale(aesthetic=aesthetic,
2264
+ name=name,
2265
+ breaks=breaks,
2266
+ labels=labels,
2267
+ lablim=lablim,
2268
+ limits=limits,
2269
+ expand=None,
2270
+ na_value=na_value,
2271
+ guide=guide,
2272
+ trans=trans,
2273
+ format=format,
2274
+ #
2275
+ start=start, end=end,
2276
+ scale_mapper_kind='color_grey')
2277
+
2278
+
2279
+ def scale_fill_grey(start=None, end=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2280
+ na_value=None, guide=None, trans=None, format=None):
2281
+ """
2282
+ Sequential grey color scale for `fill` aesthetic.
2283
+
2284
+ Parameters
2285
+ ----------
2286
+ start : float
2287
+ Gray value at low end of palette in range [0, 1].
2288
+ end : float
2289
+ Gray value at high end of palette in range [0, 1].
2290
+ name : str
2291
+ The name of the scale - used as the axis label or the legend title.
2292
+ If None, the default, the name of the scale
2293
+ is taken from the first mapping used for that aesthetic.
2294
+ breaks : list or dict
2295
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2296
+ labels : list of str or dict
2297
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2298
+ lablim : int, default=None
2299
+ The maximum label length (in characters) before trimming is applied.
2300
+ limits : list
2301
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2302
+ Discrete scale: a vector specifying the data range for the scale
2303
+ and the default order of their display in guides.
2304
+ na_value
2305
+ Missing values will be replaced with this value.
2306
+ guide
2307
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2308
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2309
+ specifying additional arguments. 'none' will hide the guide.
2310
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2311
+ Name of built-in transformation.
2312
+ format : str
2313
+ Define the format for labels on the scale. The syntax resembles Python's:
2314
+
2315
+ - '.2f' -> '12.45'
2316
+ - 'Num {}' -> 'Num 12.456789'
2317
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2318
+
2319
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2320
+
2321
+ Returns
2322
+ -------
2323
+ `FeatureSpec`
2324
+ Scale specification.
2325
+
2326
+ Notes
2327
+ -----
2328
+ Define sequential grey color scale for `fill` aesthetic.
2329
+
2330
+ Examples
2331
+ --------
2332
+ .. jupyter-execute::
2333
+ :linenos:
2334
+ :emphasize-lines: 6
2335
+
2336
+ from lets_plot import *
2337
+ LetsPlot.setup_html()
2338
+ x = list(range(50))
2339
+ ggplot({'x': x}, aes(x='x')) + \\
2340
+ geom_tile(aes(fill='x')) + \\
2341
+ scale_fill_grey(start=.9, end=.1) + \\
2342
+ coord_cartesian() + \\
2343
+ ggsize(600, 200)
2344
+
2345
+ """
2346
+ return scale_grey('fill',
2347
+ start=start, end=end,
2348
+ name=name,
2349
+ breaks=breaks,
2350
+ labels=labels,
2351
+ lablim=lablim,
2352
+ limits=limits,
2353
+ na_value=na_value,
2354
+ guide=guide,
2355
+ trans=trans,
2356
+ format=format)
2357
+
2358
+
2359
+ def scale_color_grey(start=None, end=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2360
+ na_value=None, guide=None, trans=None, format=None):
2361
+ """
2362
+ Sequential grey color scale for `color` aesthetic.
2363
+
2364
+ Parameters
2365
+ ----------
2366
+ start : float
2367
+ Gray value at low end of palette in range [0, 1].
2368
+ end : float
2369
+ Gray value at high end of palette in range [0, 1].
2370
+ name : str
2371
+ The name of the scale - used as the axis label or the legend title.
2372
+ If None, the default, the name of the scale
2373
+ is taken from the first mapping used for that aesthetic.
2374
+ breaks : list or dict
2375
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2376
+ labels : list of str or dict
2377
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2378
+ lablim : int, default=None
2379
+ The maximum label length (in characters) before trimming is applied.
2380
+ limits : list
2381
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2382
+ Discrete scale: a vector specifying the data range for the scale
2383
+ and the default order of their display in guides.
2384
+ na_value
2385
+ Missing values will be replaced with this value.
2386
+ guide
2387
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2388
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2389
+ specifying additional arguments. 'none' will hide the guide.
2390
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2391
+ Name of built-in transformation.
2392
+ format : str
2393
+ Define the format for labels on the scale. The syntax resembles Python's:
2394
+
2395
+ - '.2f' -> '12.45'
2396
+ - 'Num {}' -> 'Num 12.456789'
2397
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2398
+
2399
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2400
+
2401
+ Returns
2402
+ -------
2403
+ `FeatureSpec`
2404
+ Scale specification.
2405
+
2406
+ Notes
2407
+ -----
2408
+ Define sequential grey color scale for `color` aesthetic.
2409
+
2410
+ Examples
2411
+ --------
2412
+ .. jupyter-execute::
2413
+ :linenos:
2414
+ :emphasize-lines: 6
2415
+
2416
+ from lets_plot import *
2417
+ LetsPlot.setup_html()
2418
+ x = list(range(50))
2419
+ ggplot({'x': x}, aes(x='x')) + \\
2420
+ geom_tile(aes(color='x'), fill='white', size=3) + \\
2421
+ scale_color_grey(start=.7, end=.2) + \\
2422
+ coord_cartesian() + \\
2423
+ ggsize(600, 200)
2424
+
2425
+ """
2426
+ return scale_grey('color',
2427
+ start=start, end=end,
2428
+ name=name,
2429
+ breaks=breaks,
2430
+ labels=labels,
2431
+ lablim=lablim,
2432
+ limits=limits,
2433
+ na_value=na_value,
2434
+ guide=guide,
2435
+ trans=trans,
2436
+ format=format)
2437
+
2438
+
2439
+ def _greyscale_check_parameters(start=None, end=None):
2440
+ # Up to v.1.4.2 start/end values were in range [0,100]
2441
+ # Since v.1.4.3 start/end values are in range [0,1]
2442
+ if start != None and not (0 <= start <= 1):
2443
+ start = start / 100
2444
+ print("WARN: Value of 'start' has been scaled down to range: [0,1] : {}".format(start))
2445
+
2446
+ if end != None and not (0 <= end <= 1):
2447
+ end = end / 100
2448
+ print("WARN: Value of 'end' has been scaled down to range: [0,1] : {}".format(end))
2449
+
2450
+ if start != None and not (0 <= start <= 1):
2451
+ raise ValueError("Value of 'start' must be in range: [0,1] : {}".format(start))
2452
+
2453
+ if end != None and not (0 <= end <= 1):
2454
+ raise ValueError("Value of 'end' must be in range: [0,1] : {}".format(end))
2455
+
2456
+ return (start, end)
2457
+
2458
+
2459
+ def scale_brewer(aesthetic, *,
2460
+ type=None, palette=None, direction=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2461
+ na_value=None, guide=None, trans=None, format=None):
2462
+ """
2463
+ Sequential, diverging and qualitative color scales from colorbrewer2.org for the specified aesthetics.
2464
+ Color schemes provided are particularly suited to display discrete values (levels of factors) on a map.
2465
+
2466
+ Parameters
2467
+ ----------
2468
+ aesthetic : str or list
2469
+ The name(s) of the aesthetic(s) that this scale works with.
2470
+ type : {'seq', 'div', 'qual'}
2471
+ One of seq (sequential), div (diverging) or qual (qualitative) types of scales.
2472
+ palette : str or int
2473
+ If a string, will use that named palette. If a number, will index
2474
+ into the list of palettes of appropriate type.
2475
+ direction : {1, -1}, default=1
2476
+ Set the order of colors in the scale. If 1, colors are as output by brewer palette.
2477
+ If -1, the order of colors is reversed.
2478
+ name : str
2479
+ The name of the scale - used as the axis label or the legend title.
2480
+ If None, the default, the name of the scale
2481
+ is taken from the first mapping used for that aesthetic.
2482
+ breaks : list or dict
2483
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2484
+ labels : list of str or dict
2485
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2486
+ lablim : int, default=None
2487
+ The maximum label length (in characters) before trimming is applied.
2488
+ limits : list
2489
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2490
+ Discrete scale: a vector specifying the data range for the scale
2491
+ and the default order of their display in guides.
2492
+ na_value
2493
+ Missing values will be replaced with this value.
2494
+ guide
2495
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2496
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2497
+ specifying additional arguments. 'none' will hide the guide.
2498
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2499
+ Name of built-in transformation.
2500
+ format : str
2501
+ Define the format for labels on the scale. The syntax resembles Python's:
2502
+
2503
+ - '.2f' -> '12.45'
2504
+ - 'Num {}' -> 'Num 12.456789'
2505
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2506
+
2507
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2508
+
2509
+ Returns
2510
+ -------
2511
+ `FeatureSpec` or `FeatureSpecArray`
2512
+ Scales specification.
2513
+
2514
+ Notes
2515
+ -----
2516
+ Define sequential, diverging and qualitative color scales from colorbrewer2.org for the specified aesthetics.
2517
+ ColorBrewer provides sequential, diverging and qualitative color schemes which are particularly suited and
2518
+ tested to display discrete values (levels of a factor) on a map. It allows to smoothly interpolate 6 colors
2519
+ from any palette to a continuous scale (6 colors per palette gives nice gradients; more results in more saturated
2520
+ colors which do not look as good).
2521
+
2522
+ However, the original color schemes (particularly the qualitative ones) were not intended for this and the
2523
+ perceptual result is left to the appreciation of the user. See colorbrewer2.org for more information.
2524
+
2525
+ Palettes:
2526
+
2527
+ - Diverging : BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral.
2528
+ - Qualitative : Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3.
2529
+ - Sequential : Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd.
2530
+
2531
+ Examples
2532
+ --------
2533
+ .. jupyter-execute::
2534
+ :linenos:
2535
+ :emphasize-lines: 6
2536
+
2537
+ from lets_plot import *
2538
+ LetsPlot.setup_html()
2539
+ x = list(range(9))
2540
+ ggplot({'x': x}, aes(x='x')) + \\
2541
+ geom_tile(aes(color='x', fill='x')) + \\
2542
+ scale_brewer(aesthetic=['color', 'fill'], palette='YlGnBu') + \\
2543
+ coord_cartesian() + \\
2544
+ ggsize(600, 200)
2545
+
2546
+ """
2547
+ return _scale(aesthetic=aesthetic,
2548
+ name=name,
2549
+ breaks=breaks,
2550
+ labels=labels,
2551
+ lablim=lablim,
2552
+ limits=limits,
2553
+ expand=None,
2554
+ na_value=na_value,
2555
+ guide=guide,
2556
+ trans=trans,
2557
+ format=format,
2558
+ #
2559
+ type=type,
2560
+ palette=palette,
2561
+ direction=direction,
2562
+ scale_mapper_kind='color_brewer')
2563
+
2564
+
2565
+ def scale_fill_brewer(type=None, palette=None, direction=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2566
+ na_value=None, guide=None, trans=None, format=None):
2567
+ """
2568
+ Sequential, diverging and qualitative color scales from colorbrewer2.org for `fill` aesthetic.
2569
+ Color schemes provided are particularly suited to display discrete values (levels of factors) on a map.
2570
+
2571
+ Parameters
2572
+ ----------
2573
+ type : {'seq', 'div', 'qual'}
2574
+ One of seq (sequential), div (diverging) or qual (qualitative) types of scales.
2575
+ palette : str or int
2576
+ If a string, will use that named palette. If a number, will index
2577
+ into the list of palettes of appropriate type.
2578
+ direction : {1, -1}, default=1
2579
+ Set the order of colors in the scale. If 1, colors are as output by brewer palette.
2580
+ If -1, the order of colors is reversed.
2581
+ name : str
2582
+ The name of the scale - used as the axis label or the legend title.
2583
+ If None, the default, the name of the scale
2584
+ is taken from the first mapping used for that aesthetic.
2585
+ breaks : list or dict
2586
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2587
+ labels : list of str or dict
2588
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2589
+ lablim : int, default=None
2590
+ The maximum label length (in characters) before trimming is applied.
2591
+ limits : list
2592
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2593
+ Discrete scale: a vector specifying the data range for the scale
2594
+ and the default order of their display in guides.
2595
+ na_value
2596
+ Missing values will be replaced with this value.
2597
+ guide
2598
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2599
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2600
+ specifying additional arguments. 'none' will hide the guide.
2601
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2602
+ Name of built-in transformation.
2603
+ format : str
2604
+ Define the format for labels on the scale. The syntax resembles Python's:
2605
+
2606
+ - '.2f' -> '12.45'
2607
+ - 'Num {}' -> 'Num 12.456789'
2608
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2609
+
2610
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2611
+
2612
+ Returns
2613
+ -------
2614
+ `FeatureSpec`
2615
+ Scale specification.
2616
+
2617
+ Notes
2618
+ -----
2619
+ Define sequential, diverging and qualitative color scales from colorbrewer2.org for filling color aesthetic.
2620
+ ColorBrewer provides sequential, diverging and qualitative color schemes which are particularly suited and
2621
+ tested to display discrete values (levels of a factor) on a map. It allows to smoothly interpolate 6 colors
2622
+ from any palette to a continuous scale (6 colors per palette gives nice gradients; more results in more saturated
2623
+ colors which do not look as good).
2624
+
2625
+ However, the original color schemes (particularly the qualitative ones) were not intended for this and the
2626
+ perceptual result is left to the appreciation of the user. See colorbrewer2.org for more information.
2627
+
2628
+ Palettes:
2629
+
2630
+ - Diverging : BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral.
2631
+ - Qualitative : Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3.
2632
+ - Sequential : Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd.
2633
+
2634
+ Examples
2635
+ --------
2636
+ .. jupyter-execute::
2637
+ :linenos:
2638
+ :emphasize-lines: 6
2639
+
2640
+ from lets_plot import *
2641
+ LetsPlot.setup_html()
2642
+ x = list(range(9))
2643
+ ggplot({'x': x}, aes(x='x')) + \\
2644
+ geom_tile(aes(fill='x')) + \\
2645
+ scale_fill_brewer(palette='YlGnBu') + \\
2646
+ coord_cartesian() + \\
2647
+ ggsize(600, 200)
2648
+
2649
+ """
2650
+ return scale_brewer('fill',
2651
+ type=type,
2652
+ palette=palette,
2653
+ direction=direction,
2654
+ name=name,
2655
+ breaks=breaks,
2656
+ labels=labels,
2657
+ lablim=lablim,
2658
+ limits=limits,
2659
+ na_value=na_value,
2660
+ guide=guide,
2661
+ trans=trans,
2662
+ format=format)
2663
+
2664
+
2665
+ def scale_color_brewer(type=None, palette=None, direction=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
2666
+ na_value=None, guide=None, trans=None, format=None):
2667
+ """
2668
+ Sequential, diverging and qualitative color scales from colorbrewer2.org for `color` aesthetic.
2669
+ Color schemes provided are particularly suited to display discrete values (levels of factors) on a map.
2670
+
2671
+ Parameters
2672
+ ----------
2673
+ type : {'seq', 'div', 'qual'}
2674
+ One of seq (sequential), div (diverging) or qual (qualitative) types of scales.
2675
+ palette : str or int
2676
+ If a string, will use that named palette. If a number, will index
2677
+ into the list of palettes of appropriate type.
2678
+ direction : {1, -1}, default=1
2679
+ Set the order of colors in the scale. If 1, colors are as output by brewer palette.
2680
+ If -1, the order of colors is reversed.
2681
+ name : str
2682
+ The name of the scale - used as the axis label or the legend title.
2683
+ If None, the default, the name of the scale
2684
+ is taken from the first mapping used for that aesthetic.
2685
+ breaks : list or dict
2686
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2687
+ labels : list of str or dict
2688
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2689
+ lablim : int, default=None
2690
+ The maximum label length (in characters) before trimming is applied.
2691
+ limits : list
2692
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2693
+ Discrete scale: a vector specifying the data range for the scale
2694
+ and the default order of their display in guides.
2695
+ na_value
2696
+ Missing values will be replaced with this value.
2697
+ guide
2698
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2699
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2700
+ specifying additional arguments. 'none' will hide the guide.
2701
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2702
+ Name of built-in transformation.
2703
+ format : str
2704
+ Define the format for labels on the scale. The syntax resembles Python's:
2705
+
2706
+ - '.2f' -> '12.45'
2707
+ - 'Num {}' -> 'Num 12.456789'
2708
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2709
+
2710
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2711
+
2712
+ Returns
2713
+ -------
2714
+ `FeatureSpec`
2715
+ Scale specification.
2716
+
2717
+ Notes
2718
+ -----
2719
+ Define sequential, diverging and qualitative color scales from colorbrewer2.org for `color` aesthetic.
2720
+ ColorBrewer provides sequential, diverging and qualitative color schemes which are particularly suited and
2721
+ tested to display discrete values (levels of a factor) on a map. It allows to smoothly interpolate 6 colors
2722
+ from any palette to a continuous scale (6 colors per palette gives nice gradients; more results in more saturated
2723
+ colors which do not look as good).
2724
+
2725
+ However, the original color schemes (particularly the qualitative ones) were not intended for this and
2726
+ the perceptual result is left to the appreciation of the user. See colorbrewer2.org for more information.
2727
+
2728
+ Palettes:
2729
+
2730
+ - Diverging : BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral.
2731
+ - Qualitative : Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3.
2732
+ - Sequential : Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd.
2733
+
2734
+ Examples
2735
+ --------
2736
+ .. jupyter-execute::
2737
+ :linenos:
2738
+ :emphasize-lines: 6
2739
+
2740
+ from lets_plot import *
2741
+ LetsPlot.setup_html()
2742
+ x = list(range(10))
2743
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
2744
+ geom_point(aes(color='x'), shape=13, size=5) + \\
2745
+ scale_color_brewer(palette='Dark2', direction=-1)
2746
+
2747
+ """
2748
+ return scale_brewer('color',
2749
+ type=type,
2750
+ palette=palette,
2751
+ direction=direction,
2752
+ name=name,
2753
+ breaks=breaks,
2754
+ labels=labels,
2755
+ lablim=lablim,
2756
+ limits=limits,
2757
+ na_value=na_value,
2758
+ guide=guide,
2759
+ trans=trans,
2760
+ format=format)
2761
+
2762
+
2763
+ def scale_viridis(aesthetic, *,
2764
+ alpha=None, begin=None, end=None, direction=None, option=None,
2765
+ name=None, breaks=None, labels=None, lablim=None, limits=None,
2766
+ na_value=None, guide=None, trans=None, format=None):
2767
+ """
2768
+ The `viridis` color maps are designed to be perceptually-uniform,
2769
+ both in regular form and also when converted to black-and-white.
2770
+
2771
+ The `viridis` color scales are suitable for viewers with common forms of colour blindness.
2772
+ See also https://bids.github.io/colormap/.
2773
+
2774
+
2775
+ Parameters
2776
+ ----------
2777
+ aesthetic : str or list
2778
+ The name(s) of the aesthetic(s) that this scale works with.
2779
+ alpha : float, default=1.0
2780
+ Alpha transparency channel. (0 means transparent and 1 means opaque).
2781
+ begin : float, default=0.0
2782
+ Correspond to a color hue to start at. Accept values between 0 and 1. Should be less than `end`.
2783
+ end : float, default=1.0
2784
+ Correspond to a color hue to end with. Accept values between 0 and 1. Should be greater than `begin`.
2785
+ direction : {1, -1}, default=1
2786
+ Set the order of colors in the scale.
2787
+ If -1, the order of colors is reversed.
2788
+ option : str, default="D" (or "viridis")
2789
+ The colormap to use:
2790
+ - "magma" (or "A"),
2791
+ - "inferno" (or "B")
2792
+ - "plasma" (or "C")
2793
+ - "viridis" (or "D")
2794
+ - "cividis" (or "E")
2795
+ - "turbo"
2796
+ - "twilight"
2797
+
2798
+ name : str
2799
+ The name of the scale - used as the axis label or the legend title.
2800
+ If None, the default, the name of the scale
2801
+ is taken from the first mapping used for that aesthetic.
2802
+ breaks : list or dict
2803
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2804
+ labels : list of str or dict
2805
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2806
+ lablim : int, default=None
2807
+ The maximum label length (in characters) before trimming is applied.
2808
+ limits : list
2809
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2810
+ Discrete scale: a vector specifying the data range for the scale
2811
+ and the default order of their display in guides.
2812
+ na_value
2813
+ Missing values will be replaced with this value.
2814
+ guide
2815
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2816
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2817
+ specifying additional arguments. 'none' will hide the guide.
2818
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2819
+ Name of built-in transformation.
2820
+ format : str
2821
+ Define the format for labels on the scale. The syntax resembles Python's:
2822
+
2823
+ - '.2f' -> '12.45'
2824
+ - 'Num {}' -> 'Num 12.456789'
2825
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2826
+
2827
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2828
+
2829
+ Returns
2830
+ -------
2831
+ `FeatureSpec` or `FeatureSpecArray`
2832
+ Scales specification.
2833
+
2834
+ Notes
2835
+ -----
2836
+ Can be used for both, continuous and discrete data.
2837
+
2838
+ Examples
2839
+ --------
2840
+ .. jupyter-execute::
2841
+ :linenos:
2842
+ :emphasize-lines: 6
2843
+
2844
+ from lets_plot import *
2845
+ LetsPlot.setup_html()
2846
+ x = list(range(9))
2847
+ ggplot({'x': x}, aes(x='x')) + \\
2848
+ geom_tile(aes(color='x', fill='x')) + \\
2849
+ scale_viridis(aesthetic=['color', 'fill'], option='twilight') + \\
2850
+ coord_cartesian() + \\
2851
+ ggsize(600, 200)
2852
+
2853
+ """
2854
+
2855
+ return _scale(aesthetic=aesthetic,
2856
+ name=name,
2857
+ breaks=breaks,
2858
+ labels=labels,
2859
+ lablim=lablim,
2860
+ limits=limits,
2861
+ expand=None,
2862
+ na_value=na_value,
2863
+ guide=guide,
2864
+ trans=trans,
2865
+ format=format,
2866
+ #
2867
+ alpha=alpha,
2868
+ begin=begin,
2869
+ end=end,
2870
+ direction=direction,
2871
+ option=option,
2872
+ scale_mapper_kind='color_cmap')
2873
+
2874
+
2875
+ def scale_fill_viridis(alpha=None, begin=None, end=None, direction=None, option=None,
2876
+ name=None, breaks=None, labels=None, lablim=None, limits=None,
2877
+ na_value=None, guide=None, trans=None, format=None):
2878
+ """
2879
+ The `viridis` color maps are designed to be perceptually-uniform,
2880
+ both in regular form and also when converted to black-and-white.
2881
+
2882
+ The `viridis` color scales are suitable for viewers with common forms of colour blindness.
2883
+ See also https://bids.github.io/colormap/.
2884
+
2885
+
2886
+ Parameters
2887
+ ----------
2888
+ alpha : float, default=1.0
2889
+ Alpha transparency channel. (0 means transparent and 1 means opaque).
2890
+ begin : float, default=0.0
2891
+ Correspond to a color hue to start at. Accept values between 0 and 1. Should be less than `end`.
2892
+ end : float, default=1.0
2893
+ Correspond to a color hue to end with. Accept values between 0 and 1. Should be greater than `begin`.
2894
+ direction : {1, -1}, default=1
2895
+ Set the order of colors in the scale.
2896
+ If -1, the order of colors is reversed.
2897
+ option : str, default="D" (or "viridis")
2898
+ The colormap to use:
2899
+ - "magma" (or "A"),
2900
+ - "inferno" (or "B")
2901
+ - "plasma" (or "C")
2902
+ - "viridis" (or "D")
2903
+ - "cividis" (or "E")
2904
+ - "turbo"
2905
+ - "twilight"
2906
+
2907
+ name : str
2908
+ The name of the scale - used as the axis label or the legend title.
2909
+ If None, the default, the name of the scale
2910
+ is taken from the first mapping used for that aesthetic.
2911
+ breaks : list or dict
2912
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
2913
+ labels : list of str or dict
2914
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
2915
+ lablim : int, default=None
2916
+ The maximum label length (in characters) before trimming is applied.
2917
+ limits : list
2918
+ Continuous scale: a numeric vector of length two providing limits of the scale.
2919
+ Discrete scale: a vector specifying the data range for the scale
2920
+ and the default order of their display in guides.
2921
+ na_value
2922
+ Missing values will be replaced with this value.
2923
+ guide
2924
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
2925
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
2926
+ specifying additional arguments. 'none' will hide the guide.
2927
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
2928
+ Name of built-in transformation.
2929
+ format : str
2930
+ Define the format for labels on the scale. The syntax resembles Python's:
2931
+
2932
+ - '.2f' -> '12.45'
2933
+ - 'Num {}' -> 'Num 12.456789'
2934
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
2935
+
2936
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
2937
+
2938
+ Returns
2939
+ -------
2940
+ `FeatureSpec`
2941
+ Scale specification.
2942
+
2943
+ Notes
2944
+ -----
2945
+ Can be used for both, continuous and discrete data.
2946
+
2947
+ Examples
2948
+ --------
2949
+ .. jupyter-execute::
2950
+ :linenos:
2951
+ :emphasize-lines: 6
2952
+
2953
+ from lets_plot import *
2954
+ LetsPlot.setup_html()
2955
+ x = list(range(9))
2956
+ ggplot({'x': x}, aes(x='x')) + \\
2957
+ geom_tile(aes(fill='x')) + \\
2958
+ scale_fill_viridis(option='twilight') + \\
2959
+ coord_cartesian() + \\
2960
+ ggsize(600, 200)
2961
+
2962
+ """
2963
+ return scale_viridis('fill',
2964
+ alpha=alpha,
2965
+ begin=begin, end=end,
2966
+ direction=direction,
2967
+ option=option,
2968
+ name=name,
2969
+ breaks=breaks,
2970
+ labels=labels,
2971
+ lablim=lablim,
2972
+ limits=limits,
2973
+ na_value=na_value,
2974
+ guide=guide,
2975
+ trans=trans,
2976
+ format=format)
2977
+
2978
+
2979
+ def scale_color_viridis(alpha=None, begin=None, end=None, direction=None, option=None,
2980
+ name=None, breaks=None, labels=None, lablim=None, limits=None,
2981
+ na_value=None, guide=None, trans=None, format=None):
2982
+ """
2983
+ The `viridis` color maps are designed to be perceptually-uniform,
2984
+ both in regular form and also when converted to black-and-white.
2985
+
2986
+ The `viridis` color scales are suitable for viewers with common forms of colour blindness.
2987
+ See also https://bids.github.io/colormap/.
2988
+
2989
+
2990
+ Parameters
2991
+ ----------
2992
+ alpha : float, default=1.0
2993
+ Alpha transparency channel. (0 means transparent and 1 means opaque).
2994
+ begin : float, default=0.0
2995
+ Correspond to a color hue to start at. Accept values between 0 and 1. Should be less than `end`.
2996
+ end : float, default=1.0
2997
+ Correspond to a color hue to end with. Accept values between 0 and 1. Should be greater than `begin`.
2998
+ direction : {1, -1}, default=1
2999
+ Set the order of colors in the scale.
3000
+ If -1, the order of colors is reversed.
3001
+ option : str, default="D" (or "viridis")
3002
+ The colormap to use:
3003
+ - "magma" (or "A"),
3004
+ - "inferno" (or "B")
3005
+ - "plasma" (or "C")
3006
+ - "viridis" (or "D")
3007
+ - "cividis" (or "E")
3008
+ - "turbo"
3009
+ - "twilight"
3010
+
3011
+ name : str
3012
+ The name of the scale - used as the axis label or the legend title.
3013
+ If None, the default, the name of the scale
3014
+ is taken from the first mapping used for that aesthetic.
3015
+ breaks : list or dict
3016
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3017
+ labels : list of str or dict
3018
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3019
+ lablim : int, default=None
3020
+ The maximum label length (in characters) before trimming is applied.
3021
+ limits : list
3022
+ Continuous scale: a numeric vector of length two providing limits of the scale.
3023
+ Discrete scale: a vector specifying the data range for the scale
3024
+ and the default order of their display in guides.
3025
+ na_value
3026
+ Missing values will be replaced with this value.
3027
+ guide
3028
+ Guide to use for this scale. It can either be a string ('colorbar', 'legend')
3029
+ or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
3030
+ specifying additional arguments. 'none' will hide the guide.
3031
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3032
+ Name of built-in transformation.
3033
+ format : str
3034
+ Define the format for labels on the scale. The syntax resembles Python's:
3035
+
3036
+ - '.2f' -> '12.45'
3037
+ - 'Num {}' -> 'Num 12.456789'
3038
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3039
+
3040
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3041
+
3042
+ Returns
3043
+ -------
3044
+ `FeatureSpec`
3045
+ Scale specification.
3046
+
3047
+ Notes
3048
+ -----
3049
+ Can be used for both, continuous and discrete data.
3050
+
3051
+ Examples
3052
+ --------
3053
+ .. jupyter-execute::
3054
+ :linenos:
3055
+ :emphasize-lines: 6
3056
+
3057
+ from lets_plot import *
3058
+ LetsPlot.setup_html()
3059
+ x = list(range(10))
3060
+ ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
3061
+ geom_point(aes(color='x'), shape=13, size=5) + \\
3062
+ scale_color_viridis(option='cividis', direction=-1)
3063
+
3064
+ """
3065
+ return scale_viridis('color',
3066
+ alpha=alpha,
3067
+ begin=begin, end=end,
3068
+ direction=direction,
3069
+ option=option,
3070
+ name=name,
3071
+ breaks=breaks,
3072
+ labels=labels,
3073
+ lablim=lablim,
3074
+ limits=limits,
3075
+ na_value=na_value,
3076
+ guide=guide,
3077
+ trans=trans,
3078
+ format=format)
3079
+
3080
+ #
3081
+ # Range Scale (alpha and size)
3082
+ #
3083
+
3084
+ def scale_alpha(range=None, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, trans=None,
3085
+ format=None):
3086
+ """
3087
+ Scale for alpha.
3088
+
3089
+ Parameters
3090
+ ----------
3091
+ range : list
3092
+ The range of the mapped aesthetics result.
3093
+ name : str
3094
+ The name of the scale - used as the axis label or the legend title.
3095
+ If None, the default, the name of the scale
3096
+ is taken from the first mapping used for that aesthetic.
3097
+ breaks : list or dict
3098
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3099
+ labels : list of str or dict
3100
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3101
+ lablim : int, default=None
3102
+ The maximum label length (in characters) before trimming is applied.
3103
+ limits : list
3104
+ A vector specifying the data range for the scale
3105
+ and the default order of their display in guides.
3106
+ na_value
3107
+ Missing values will be replaced with this value.
3108
+ guide
3109
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
3110
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3111
+ Name of built-in transformation.
3112
+ format : str
3113
+ Define the format for labels on the scale. The syntax resembles Python's:
3114
+
3115
+ - '.2f' -> '12.45'
3116
+ - 'Num {}' -> 'Num 12.456789'
3117
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3118
+
3119
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3120
+
3121
+ Returns
3122
+ -------
3123
+ `FeatureSpec`
3124
+ Scale specification.
3125
+
3126
+ Examples
3127
+ --------
3128
+ .. jupyter-execute::
3129
+ :linenos:
3130
+ :emphasize-lines: 9
3131
+
3132
+ import numpy as np
3133
+ from lets_plot import *
3134
+ LetsPlot.setup_html()
3135
+ np.random.seed(100)
3136
+ x = np.random.normal(0, 1, 1000)
3137
+ y = np.random.normal(0, 1, 1000)
3138
+ ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
3139
+ geom_point(aes(alpha='..density..'), stat='density2d', contour=False, n=30) + \\
3140
+ scale_alpha(range=[.01, .99])
3141
+
3142
+ """
3143
+ return _scale('alpha',
3144
+ name=name,
3145
+ breaks=breaks,
3146
+ labels=labels,
3147
+ lablim=lablim,
3148
+ limits=limits,
3149
+ expand=None,
3150
+ na_value=na_value,
3151
+ guide=guide,
3152
+ trans=trans,
3153
+ format=format,
3154
+ #
3155
+ range=range)
3156
+
3157
+
3158
+ def scale_size(range=None, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, trans=None,
3159
+ format=None):
3160
+ """
3161
+ Scale for size.
3162
+
3163
+ Parameters
3164
+ ----------
3165
+ range : list
3166
+ The range of the mapped aesthetics result.
3167
+ name : str
3168
+ The name of the scale - used as the axis label or the legend title.
3169
+ If None, the default, the name of the scale
3170
+ is taken from the first mapping used for that aesthetic.
3171
+ breaks : list or dict
3172
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3173
+ labels : list of str or dict
3174
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3175
+ lablim : int, default=None
3176
+ The maximum label length (in characters) before trimming is applied.
3177
+ limits : list
3178
+ A vector specifying the data range for the scale
3179
+ and the default order of their display in guides.
3180
+ na_value
3181
+ Missing values will be replaced with this value.
3182
+ guide
3183
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
3184
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3185
+ Name of built-in transformation.
3186
+ format : str
3187
+ Define the format for labels on the scale. The syntax resembles Python's:
3188
+
3189
+ - '.2f' -> '12.45'
3190
+ - 'Num {}' -> 'Num 12.456789'
3191
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3192
+
3193
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3194
+
3195
+ Returns
3196
+ -------
3197
+ `FeatureSpec`
3198
+ Scale specification.
3199
+
3200
+ Examples
3201
+ --------
3202
+ .. jupyter-execute::
3203
+ :linenos:
3204
+ :emphasize-lines: 10
3205
+
3206
+ import numpy as np
3207
+ from lets_plot import *
3208
+ LetsPlot.setup_html()
3209
+ np.random.seed(100)
3210
+ n = 50
3211
+ x = np.random.rand(n)
3212
+ y = np.random.rand(n)
3213
+ area = np.power(np.random.randint(30, size=n), 2)
3214
+ ggplot() + geom_point(aes(x, y, size=area), alpha=0.7) + \\
3215
+ scale_size(range=[3, 13])
3216
+
3217
+ """
3218
+ return _scale('size',
3219
+ name=name,
3220
+ breaks=breaks,
3221
+ labels=labels,
3222
+ lablim=lablim,
3223
+ limits=limits,
3224
+ expand=None,
3225
+ na_value=na_value,
3226
+ guide=guide,
3227
+ trans=trans,
3228
+ format=format,
3229
+ #
3230
+ range=range)
3231
+
3232
+
3233
+ def scale_size_area(max_size=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
3234
+ na_value=None, guide=None, trans=None, format=None):
3235
+ """
3236
+ Continuous scale for size that maps 0 to 0.
3237
+
3238
+ Parameters
3239
+ ----------
3240
+ max_size : float
3241
+ The max size that is mapped to.
3242
+ name : str
3243
+ The name of the scale - used as the axis label or the legend title.
3244
+ If None, the default, the name of the scale
3245
+ is taken from the first mapping used for that aesthetic.
3246
+ breaks : list or dict
3247
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3248
+ labels : list of str or dict
3249
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3250
+ lablim : int, default=None
3251
+ The maximum label length (in characters) before trimming is applied.
3252
+ limits : list
3253
+ A vector specifying the data range for the scale
3254
+ and the default order of their display in guides.
3255
+ na_value
3256
+ Missing values will be replaced with this value.
3257
+ guide
3258
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
3259
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3260
+ Name of built-in transformation.
3261
+ format : str
3262
+ Define the format for labels on the scale. The syntax resembles Python's:
3263
+
3264
+ - '.2f' -> '12.45'
3265
+ - 'Num {}' -> 'Num 12.456789'
3266
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3267
+
3268
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3269
+
3270
+ Returns
3271
+ -------
3272
+ `FeatureSpec`
3273
+ Scale specification.
3274
+
3275
+ Notes
3276
+ -----
3277
+ This method maps 0 data to 0 size. Useful in some stats such as count.
3278
+
3279
+ Examples
3280
+ --------
3281
+ .. jupyter-execute::
3282
+ :linenos:
3283
+ :emphasize-lines: 10
3284
+
3285
+ import numpy as np
3286
+ from lets_plot import *
3287
+ LetsPlot.setup_html()
3288
+ np.random.seed(100)
3289
+ n = 50
3290
+ x = np.random.rand(n)
3291
+ y = np.random.rand(n)
3292
+ area = np.power(np.random.uniform(30, size=n), 2)
3293
+ ggplot() + geom_point(aes(x, y, size=area), alpha=0.7) + \\
3294
+ scale_size_area(max_size=15)
3295
+
3296
+ """
3297
+ return _scale('size',
3298
+ name=name,
3299
+ breaks=breaks,
3300
+ labels=labels,
3301
+ lablim=lablim,
3302
+ limits=limits,
3303
+ expand=None,
3304
+ na_value=na_value,
3305
+ guide=guide,
3306
+ trans=trans,
3307
+ format=format,
3308
+ #
3309
+ max_size=max_size,
3310
+ scale_mapper_kind='size_area')
3311
+
3312
+
3313
+ def scale_linewidth(range=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
3314
+ na_value=None, guide=None, trans=None, format=None):
3315
+ """
3316
+ Scale for linewidth.
3317
+
3318
+ Parameters
3319
+ ----------
3320
+ range : list
3321
+ The range of the mapped aesthetics result.
3322
+ name : str
3323
+ The name of the scale - used as the axis label or the legend title.
3324
+ If None, the default, the name of the scale
3325
+ is taken from the first mapping used for that aesthetic.
3326
+ breaks : list or dict
3327
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3328
+ labels : list of str or dict
3329
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3330
+ lablim : int, default=None
3331
+ The maximum label length (in characters) before trimming is applied.
3332
+ limits : list
3333
+ A vector specifying the data range for the scale
3334
+ and the default order of their display in guides.
3335
+ na_value
3336
+ Missing values will be replaced with this value.
3337
+ guide
3338
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
3339
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3340
+ Name of built-in transformation.
3341
+ format : str
3342
+ Define the format for labels on the scale. The syntax resembles Python's:
3343
+
3344
+ - '.2f' -> '12.45'
3345
+ - 'Num {}' -> 'Num 12.456789'
3346
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3347
+
3348
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3349
+
3350
+ Returns
3351
+ -------
3352
+ `FeatureSpec`
3353
+ Scale specification.
3354
+
3355
+ Examples
3356
+ --------
3357
+ .. jupyter-execute::
3358
+ :linenos:
3359
+ :emphasize-lines: 9
3360
+
3361
+ from lets_plot import *
3362
+ LetsPlot.setup_html()
3363
+ data = {
3364
+ 'x': [0, 1, 2],
3365
+ 'y': [1, 2, 1],
3366
+ 'w': ['a', 'b', 'c'],
3367
+ }
3368
+ ggplot(data, aes('x', 'y')) + geom_lollipop(aes(linewidth='w')) + \\
3369
+ scale_linewidth(range=[.5, 2])
3370
+
3371
+ """
3372
+ return _scale('linewidth',
3373
+ name=name,
3374
+ breaks=breaks,
3375
+ labels=labels,
3376
+ lablim=lablim,
3377
+ limits=limits,
3378
+ expand=None,
3379
+ na_value=na_value,
3380
+ guide=guide,
3381
+ trans=trans,
3382
+ format=format,
3383
+ #
3384
+ range=range)
3385
+
3386
+
3387
+ def scale_stroke(range=None, name=None, breaks=None, labels=None, lablim=None, limits=None,
3388
+ na_value=None, guide=None, trans=None, format=None):
3389
+ """
3390
+ Scale for stroke.
3391
+
3392
+ Parameters
3393
+ ----------
3394
+ range : list
3395
+ The range of the mapped aesthetics result.
3396
+ name : str
3397
+ The name of the scale - used as the axis label or the legend title.
3398
+ If None, the default, the name of the scale
3399
+ is taken from the first mapping used for that aesthetic.
3400
+ breaks : list or dict
3401
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3402
+ labels : list of str or dict
3403
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3404
+ lablim : int, default=None
3405
+ The maximum label length (in characters) before trimming is applied.
3406
+ limits : list
3407
+ A vector specifying the data range for the scale
3408
+ and the default order of their display in guides.
3409
+ na_value
3410
+ Missing values will be replaced with this value.
3411
+ guide
3412
+ A result returned by `guide_legend()` function or 'none' to hide the guide.
3413
+ trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
3414
+ Name of built-in transformation.
3415
+ format : str
3416
+ Define the format for labels on the scale. The syntax resembles Python's:
3417
+
3418
+ - '.2f' -> '12.45'
3419
+ - 'Num {}' -> 'Num 12.456789'
3420
+ - 'TTL: {.2f}$' -> 'TTL: 12.45$'
3421
+
3422
+ For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
3423
+
3424
+ Returns
3425
+ -------
3426
+ `FeatureSpec`
3427
+ Scale specification.
3428
+
3429
+ Examples
3430
+ --------
3431
+ .. jupyter-execute::
3432
+ :linenos:
3433
+ :emphasize-lines: 9
3434
+
3435
+ from lets_plot import *
3436
+ LetsPlot.setup_html()
3437
+ data = {
3438
+ 'x': [0, 1, 2],
3439
+ 'y': [1, 2, 1],
3440
+ 's': ['a', 'b', 'c'],
3441
+ }
3442
+ ggplot(data, aes('x', 'y')) + geom_lollipop(aes(stroke='s')) + \\
3443
+ scale_stroke(range=[.5, 2])
3444
+
3445
+ """
3446
+ return _scale('stroke',
3447
+ name=name,
3448
+ breaks=breaks,
3449
+ labels=labels,
3450
+ lablim=lablim,
3451
+ limits=limits,
3452
+ expand=None,
3453
+ na_value=na_value,
3454
+ guide=guide,
3455
+ trans=trans,
3456
+ format=format,
3457
+ #
3458
+ range=range)
3459
+
3460
+
3461
+ def _scale(aesthetic, *,
3462
+ name=None,
3463
+ breaks=None, labels=None,
3464
+ lablim=None,
3465
+ limits=None,
3466
+ expand=None,
3467
+ na_value=None,
3468
+ trans=None,
3469
+ guide=None,
3470
+ format=None,
3471
+ position=None,
3472
+ **kwargs):
3473
+ """
3474
+ Create a scale (discrete or continuous)
3475
+
3476
+ Parameters
3477
+ ----------
3478
+ aesthetic : str or list
3479
+ The name(s) of the aesthetic(s) that this scale works with.
3480
+ name : str
3481
+ The name of the scale - used as the axis label or the legend title
3482
+ breaks : list or dict
3483
+ A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
3484
+ labels : list of str or dict
3485
+ A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
3486
+ lablim : int, default=None
3487
+ The maximum label length (in characters) before trimming is applied.
3488
+ limits : list
3489
+ A numeric vector of length two providing limits of the scale.
3490
+ expand : list
3491
+ A numeric vector of length two giving multiplicative and additive expansion constants.
3492
+ na_value
3493
+ Value to use for missing values
3494
+ trans : str
3495
+ Name of built-in transformation.
3496
+ guide
3497
+ Type of legend. Use 'colorbar' for continuous color bar, or 'legend' for discrete values.
3498
+ format : str
3499
+ A string of the format for labels on the scale. Supported types are number and date/time.
3500
+ position : str
3501
+ For position scales,
3502
+ The position of the axis:
3503
+ - 'left', 'right' or 'both' for y-axis;
3504
+ - 'top', 'bottom' or 'both' for x-axis.
3505
+
3506
+ Returns
3507
+ -------
3508
+ `FeatureSpec` or `FeatureSpecArray`
3509
+ Scales specification.
3510
+
3511
+ """
3512
+
3513
+ # flatten the 'other' sub-dictionary
3514
+ args = locals().copy()
3515
+ args.pop('kwargs')
3516
+
3517
+ # 'breaks' - dict of labels as keys and breaks as values
3518
+ if isinstance(breaks, dict):
3519
+ if labels is None:
3520
+ args['labels'] = list(breaks.keys())
3521
+ breaks = list(breaks.values())
3522
+ args['breaks'] = breaks
3523
+
3524
+ # 'labels' - dict of breaks as keys and labels as values
3525
+ if isinstance(labels, dict):
3526
+ if breaks is None:
3527
+ args['breaks'] = list(labels.keys())
3528
+ args['labels'] = list(labels.values())
3529
+ else:
3530
+ new_labels = []
3531
+ new_breaks = []
3532
+ for break_value in breaks:
3533
+ if break_value in labels:
3534
+ new_labels.append(labels[break_value])
3535
+ new_breaks.append(break_value)
3536
+
3537
+ breaks_without_label = [item for item in breaks if item not in new_breaks] # keeps order
3538
+ args['breaks'] = new_breaks + breaks_without_label
3539
+ args['labels'] = new_labels
3540
+
3541
+ specs = []
3542
+ if isinstance(aesthetic, list):
3543
+ args.pop('aesthetic')
3544
+ for aes in aesthetic:
3545
+ specs.append(FeatureSpec('scale', aesthetic=aes, **args, **kwargs))
3546
+ else:
3547
+ specs.append(FeatureSpec('scale', **args, **kwargs))
3548
+
3549
+ if len(specs) == 1:
3550
+ return specs[0]
3551
+
3552
+ return FeatureSpecArray(*specs)