lets-plot 4.8.1rc1__cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

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