lets-plot 4.3.3__cp310-cp310-win_amd64.whl → 4.4.0__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lets-plot might be problematic. Click here for more details.
- lets_plot/__init__.py +2 -0
- lets_plot/_type_utils.py +8 -0
- lets_plot/_version.py +1 -1
- lets_plot/bistro/__init__.py +3 -1
- lets_plot/bistro/corr.py +3 -3
- lets_plot/bistro/im.py +1 -1
- lets_plot/bistro/qq.py +2 -0
- lets_plot/bistro/residual.py +8 -3
- lets_plot/bistro/waterfall.py +243 -0
- lets_plot/geo_data/to_geo_data_frame.py +5 -1
- lets_plot/mapping.py +6 -7
- lets_plot/package_data/lets-plot.min.js +1 -1
- lets_plot/plot/__init__.py +5 -1
- lets_plot/plot/annotation.py +2 -4
- lets_plot/plot/coord.py +1 -2
- lets_plot/plot/core.py +25 -30
- lets_plot/plot/geom.py +471 -121
- lets_plot/plot/geom_function_.py +7 -2
- lets_plot/plot/geom_imshow_.py +1 -1
- lets_plot/plot/geom_livemap_.py +4 -0
- lets_plot/plot/ggtb_.py +11 -0
- lets_plot/plot/guide.py +94 -8
- lets_plot/plot/label.py +30 -6
- lets_plot/plot/marginal_layer.py +1 -2
- lets_plot/plot/plot.py +4 -2
- lets_plot/plot/scale_colormap_mpl.py +295 -0
- lets_plot/plot/series_meta.py +123 -0
- lets_plot/plot/stat.py +2 -4
- lets_plot/plot/theme_.py +12 -0
- lets_plot/plot/tooltip.py +24 -24
- lets_plot/plot/util.py +106 -113
- {lets_plot-4.3.3.dist-info → lets_plot-4.4.0.dist-info}/METADATA +24 -48
- {lets_plot-4.3.3.dist-info → lets_plot-4.4.0.dist-info}/RECORD +37 -33
- {lets_plot-4.3.3.dist-info → lets_plot-4.4.0.dist-info}/WHEEL +1 -1
- lets_plot_kotlin_bridge.cp310-win_amd64.pyd +0 -0
- {lets_plot-4.3.3.dist-info → lets_plot-4.4.0.dist-info}/LICENSE +0 -0
- {lets_plot-4.3.3.dist-info → lets_plot-4.4.0.dist-info}/top_level.txt +0 -0
lets_plot/plot/geom_function_.py
CHANGED
|
@@ -75,7 +75,8 @@ def _get_mapping(mapping):
|
|
|
75
75
|
return aes(**{**x_mapping_dict, **mapping_dict, **y_mapping_dict})
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def geom_function(mapping=None, *, data=None, stat=None, geom=None, position=None, show_legend=None,
|
|
78
|
+
def geom_function(mapping=None, *, data=None, stat=None, geom=None, position=None, show_legend=None, manual_key=None,
|
|
79
|
+
tooltips=None,
|
|
79
80
|
fun=None, xlim=None, n=None,
|
|
80
81
|
color_by=None,
|
|
81
82
|
**other_args):
|
|
@@ -104,6 +105,9 @@ def geom_function(mapping=None, *, data=None, stat=None, geom=None, position=Non
|
|
|
104
105
|
'stack' or 'identity', or the result of calling a position adjustment function (e.g., `position_dodge()` etc.).
|
|
105
106
|
show_legend : bool, default=True
|
|
106
107
|
False - do not show legend for this layer.
|
|
108
|
+
manual_key : str or `layer_key`
|
|
109
|
+
The key to show in the manual legend.
|
|
110
|
+
Specify text for the legend label or advanced settings using the `layer_key()` function.
|
|
107
111
|
tooltips : `layer_tooltips`
|
|
108
112
|
Result of the call to the `layer_tooltips()` function.
|
|
109
113
|
Specify appearance, style and content.
|
|
@@ -133,7 +137,7 @@ def geom_function(mapping=None, *, data=None, stat=None, geom=None, position=Non
|
|
|
133
137
|
- x : x-axis value.
|
|
134
138
|
- alpha : transparency level of a layer. Accept values between 0 and 1.
|
|
135
139
|
- color (colour) : color of the geometry. String in the following formats: RGB/RGBA (e.g. "rgb(0, 0, 255)"); HEX (e.g. "#0000FF"); color name (e.g. "red"); role name ("pen", "paper" or "brush").
|
|
136
|
-
- linetype : type of the line. Codes and names: 0 = 'blank', 1 = 'solid', 2 = 'dashed', 3 = 'dotted', 4 = 'dotdash', 5 = 'longdash', 6 = 'twodash'.
|
|
140
|
+
- linetype : type of the line. Codes and names: 0 = 'blank', 1 = 'solid', 2 = 'dashed', 3 = 'dotted', 4 = 'dotdash', 5 = 'longdash', 6 = 'twodash'. For more info see https://lets-plot.org/python/pages/aesthetics.html#line-types.
|
|
137
141
|
- size : line width.
|
|
138
142
|
|
|
139
143
|
Examples
|
|
@@ -195,6 +199,7 @@ def geom_function(mapping=None, *, data=None, stat=None, geom=None, position=Non
|
|
|
195
199
|
stat=fun_stat,
|
|
196
200
|
position=position,
|
|
197
201
|
show_legend=show_legend,
|
|
202
|
+
manual_key=manual_key,
|
|
198
203
|
sampling=None,
|
|
199
204
|
tooltips=tooltips,
|
|
200
205
|
color_by=color_by,
|
lets_plot/plot/geom_imshow_.py
CHANGED
lets_plot/plot/geom_livemap_.py
CHANGED
|
@@ -86,6 +86,10 @@ def geom_livemap(*,
|
|
|
86
86
|
-----
|
|
87
87
|
`geom_livemap()` draws a map, which can be dragged and zoomed.
|
|
88
88
|
|
|
89
|
+
----
|
|
90
|
+
|
|
91
|
+
By default the livemap area has a non-zero inset. You can get rid of this with the theme: `theme(plot_inset=0)`.
|
|
92
|
+
|
|
89
93
|
Examples
|
|
90
94
|
--------
|
|
91
95
|
.. jupyter-execute::
|
lets_plot/plot/ggtb_.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2024. 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
|
|
6
|
+
|
|
7
|
+
__all__ = ['ggtb']
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def ggtb():
|
|
11
|
+
return FeatureSpec(kind='ggtoolbar', name=None)
|
lets_plot/plot/guide.py
CHANGED
|
@@ -4,21 +4,27 @@
|
|
|
4
4
|
#
|
|
5
5
|
from .core import FeatureSpec
|
|
6
6
|
|
|
7
|
-
__all__ = ['guide_legend', 'guide_colorbar', 'guides']
|
|
7
|
+
__all__ = ['guide_legend', 'guide_colorbar', 'guides', 'layer_key']
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def guide_legend(nrow=None, ncol=None, byrow=None):
|
|
10
|
+
def guide_legend(title=None, *, nrow=None, ncol=None, byrow=None, override_aes=None):
|
|
11
11
|
"""
|
|
12
12
|
Legend guide.
|
|
13
13
|
|
|
14
14
|
Parameters
|
|
15
15
|
----------
|
|
16
|
+
title : str
|
|
17
|
+
Title of guide.
|
|
16
18
|
nrow : int
|
|
17
19
|
Number of rows in legend's guide.
|
|
18
20
|
ncol : int
|
|
19
21
|
Number of columns in legend's guide.
|
|
20
22
|
byrow : bool, default=True
|
|
21
23
|
Type of output: by row, or by column.
|
|
24
|
+
override_aes : dict
|
|
25
|
+
Dictionary that maps aesthetic parameters to new values, overriding the default legend appearance.
|
|
26
|
+
Each value can be a constant applied to all keys or a list that changes particular keys.
|
|
27
|
+
|
|
22
28
|
|
|
23
29
|
Returns
|
|
24
30
|
-------
|
|
@@ -45,18 +51,20 @@ def guide_legend(nrow=None, ncol=None, byrow=None):
|
|
|
45
51
|
c = np.random.choice(list('abcdefgh'), size=n)
|
|
46
52
|
ggplot({'x': x, 'y': y, 'c': c}, aes('x', 'y')) + \\
|
|
47
53
|
geom_point(aes(shape='c'), size=4, alpha=.7) + \\
|
|
48
|
-
scale_shape(guide=guide_legend(nrow=3))
|
|
54
|
+
scale_shape(guide=guide_legend(nrow=3, override_aes={'color': 'red'}))
|
|
49
55
|
|
|
50
56
|
"""
|
|
51
57
|
return _guide('legend', **locals())
|
|
52
58
|
|
|
53
59
|
|
|
54
|
-
def guide_colorbar(barwidth=None, barheight=None, nbin=None):
|
|
60
|
+
def guide_colorbar(title=None, *, barwidth=None, barheight=None, nbin=None):
|
|
55
61
|
"""
|
|
56
62
|
Continuous color bar guide.
|
|
57
63
|
|
|
58
64
|
Parameters
|
|
59
65
|
----------
|
|
66
|
+
title : str
|
|
67
|
+
Title of guide.
|
|
60
68
|
barwidth : float
|
|
61
69
|
Color bar width in px.
|
|
62
70
|
barheight : float
|
|
@@ -98,6 +106,8 @@ def guide_colorbar(barwidth=None, barheight=None, nbin=None):
|
|
|
98
106
|
|
|
99
107
|
|
|
100
108
|
def _guide(name, **kwargs):
|
|
109
|
+
if 'title' in kwargs and isinstance(kwargs['title'], int):
|
|
110
|
+
raise ValueError("Use keyword arguments for all other than 'title' parameters.")
|
|
101
111
|
return FeatureSpec('guide', name=name, **kwargs)
|
|
102
112
|
|
|
103
113
|
|
|
@@ -108,10 +118,17 @@ def guides(**kwargs):
|
|
|
108
118
|
Parameters
|
|
109
119
|
----------
|
|
110
120
|
kwargs
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
Key-value pairs where the key can be:
|
|
122
|
+
|
|
123
|
+
- An aesthetic name
|
|
124
|
+
- 'manual' - a key referring to the default custom legend
|
|
125
|
+
- A group name referring to a custom legend where the group is defined via the `layer_key()` function
|
|
126
|
+
|
|
127
|
+
The value can be either:
|
|
128
|
+
|
|
129
|
+
- A string ('colorbar', 'legend')
|
|
130
|
+
- A call to a guide function (`guide_colorbar()`, `guide_legend()`) specifying additional arguments
|
|
131
|
+
- 'none' to hide the guide
|
|
115
132
|
|
|
116
133
|
Returns
|
|
117
134
|
-------
|
|
@@ -139,5 +156,74 @@ def guides(**kwargs):
|
|
|
139
156
|
guides(shape=guide_legend(ncol=2), \\
|
|
140
157
|
color=guide_colorbar(nbin=8, barwidth=20))
|
|
141
158
|
|
|
159
|
+
|
|
|
160
|
+
|
|
161
|
+
.. jupyter-execute::
|
|
162
|
+
:linenos:
|
|
163
|
+
:emphasize-lines: 11
|
|
164
|
+
|
|
165
|
+
import numpy as np
|
|
166
|
+
from lets_plot import *
|
|
167
|
+
LetsPlot.setup_html()
|
|
168
|
+
n = 10
|
|
169
|
+
np.random.seed(42)
|
|
170
|
+
x = list(range(n))
|
|
171
|
+
y = np.random.uniform(size=n)
|
|
172
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
173
|
+
geom_point(color='red', manual_key="point") + \\
|
|
174
|
+
geom_line(color='blue', manual_key="line") + \\
|
|
175
|
+
guides(manual=guide_legend('Zones', ncol=2))
|
|
176
|
+
|
|
142
177
|
"""
|
|
143
178
|
return FeatureSpec('guides', name=None, **kwargs)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def layer_key(label, group=None, *, index=None, **kwargs):
|
|
182
|
+
"""
|
|
183
|
+
Configure custom legend.
|
|
184
|
+
|
|
185
|
+
Parameters
|
|
186
|
+
----------
|
|
187
|
+
label : str
|
|
188
|
+
Text for the element in the custom legend.
|
|
189
|
+
group : str, default='manual'
|
|
190
|
+
Group name by which elements are combined into a legend group.
|
|
191
|
+
index : int
|
|
192
|
+
Position of the element in the custom legend.
|
|
193
|
+
kwargs :
|
|
194
|
+
A list of aesthetic parameters to use in the custom legend.
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
`FeatureSpec`
|
|
199
|
+
Custom legend specification.
|
|
200
|
+
|
|
201
|
+
Notes
|
|
202
|
+
-----
|
|
203
|
+
The group name specified with the `group` parameter can be used in the `labs()` and `guides()` functions
|
|
204
|
+
to further customize the display of this group (e.g. change its name).
|
|
205
|
+
In particular, items in the 'manual' group will be displayed without a title unless you change it manually.
|
|
206
|
+
|
|
207
|
+
|
|
|
208
|
+
|
|
209
|
+
If you set the same group and label for a legend element in different layers, they will merge into one complex legend element.
|
|
210
|
+
|
|
211
|
+
Examples
|
|
212
|
+
--------
|
|
213
|
+
.. jupyter-execute::
|
|
214
|
+
:linenos:
|
|
215
|
+
:emphasize-lines: 9-10
|
|
216
|
+
|
|
217
|
+
import numpy as np
|
|
218
|
+
from lets_plot import *
|
|
219
|
+
LetsPlot.setup_html()
|
|
220
|
+
n = 10
|
|
221
|
+
np.random.seed(42)
|
|
222
|
+
x = list(range(n))
|
|
223
|
+
y = np.random.uniform(size=n)
|
|
224
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
225
|
+
geom_point(color='red', manual_key=layer_key("point", shape=21)) + \\
|
|
226
|
+
geom_line(color='blue', linetype=2, manual_key=layer_key("line", linetype=1))
|
|
227
|
+
|
|
228
|
+
"""
|
|
229
|
+
return FeatureSpec('layer_key', name=None, label=label, group=group, index=index, **kwargs)
|
lets_plot/plot/label.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
4
4
|
#
|
|
5
5
|
from .core import FeatureSpec, FeatureSpecArray
|
|
6
|
-
from .
|
|
6
|
+
from .guide import _guide, guides
|
|
7
7
|
|
|
8
8
|
#
|
|
9
9
|
# Plot title
|
|
@@ -112,7 +112,7 @@ def ylab(label):
|
|
|
112
112
|
|
|
113
113
|
def labs(title=None, subtitle=None, caption=None, **labels):
|
|
114
114
|
"""
|
|
115
|
-
Change plot title and
|
|
115
|
+
Change plot title, axis labels and legend titles.
|
|
116
116
|
|
|
117
117
|
Parameters
|
|
118
118
|
----------
|
|
@@ -123,7 +123,13 @@ def labs(title=None, subtitle=None, caption=None, **labels):
|
|
|
123
123
|
caption : str
|
|
124
124
|
The text for the plot caption.
|
|
125
125
|
labels
|
|
126
|
-
Name-value pairs where name
|
|
126
|
+
Name-value pairs where the name can be:
|
|
127
|
+
|
|
128
|
+
- An aesthetic name
|
|
129
|
+
- 'manual' - a key referring to the default custom legend
|
|
130
|
+
- A group name referring to a custom legend where the group is defined via the `layer_key()` function
|
|
131
|
+
|
|
132
|
+
The value should be a string, e.g. `color="New Color label"`.
|
|
127
133
|
|
|
128
134
|
Returns
|
|
129
135
|
-------
|
|
@@ -143,6 +149,24 @@ def labs(title=None, subtitle=None, caption=None, **labels):
|
|
|
143
149
|
labs(title='New plot title', subtitle='The plot subtitle', caption='The plot caption', \\
|
|
144
150
|
x='New x axis label', y='New y axis label', size='New legend title')
|
|
145
151
|
|
|
152
|
+
|
|
|
153
|
+
|
|
154
|
+
.. jupyter-execute::
|
|
155
|
+
:linenos:
|
|
156
|
+
:emphasize-lines: 11
|
|
157
|
+
|
|
158
|
+
import numpy as np
|
|
159
|
+
from lets_plot import *
|
|
160
|
+
LetsPlot.setup_html()
|
|
161
|
+
n = 10
|
|
162
|
+
np.random.seed(42)
|
|
163
|
+
x = list(range(n))
|
|
164
|
+
y = np.random.uniform(size=n)
|
|
165
|
+
ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
|
|
166
|
+
geom_point(color='red', manual_key="point") + \\
|
|
167
|
+
geom_line(color='blue', manual_key="line") + \\
|
|
168
|
+
labs(manual='Zones')
|
|
169
|
+
|
|
146
170
|
"""
|
|
147
171
|
specs = []
|
|
148
172
|
|
|
@@ -154,9 +178,9 @@ def labs(title=None, subtitle=None, caption=None, **labels):
|
|
|
154
178
|
if caption is not None:
|
|
155
179
|
specs.append(FeatureSpec('caption', name=None, text=caption))
|
|
156
180
|
|
|
157
|
-
#
|
|
158
|
-
for
|
|
159
|
-
specs.append(
|
|
181
|
+
# guides
|
|
182
|
+
for key, label in labels.items():
|
|
183
|
+
specs.append(guides(**{key: _guide(name=None, title=label)}))
|
|
160
184
|
|
|
161
185
|
if len(specs) == 1:
|
|
162
186
|
return specs[0]
|
lets_plot/plot/marginal_layer.py
CHANGED
|
@@ -41,11 +41,10 @@ def ggmarginal(sides: str, *, size=None, layer: Union[LayerSpec, FeatureSpecArra
|
|
|
41
41
|
--------
|
|
42
42
|
.. jupyter-execute::
|
|
43
43
|
:linenos:
|
|
44
|
-
:emphasize-lines:
|
|
44
|
+
:emphasize-lines: 23
|
|
45
45
|
|
|
46
46
|
import numpy as np
|
|
47
47
|
from lets_plot import *
|
|
48
|
-
from lets_plot.mapping import as_discrete
|
|
49
48
|
LetsPlot.setup_html()
|
|
50
49
|
LetsPlot.set_theme(theme_light())
|
|
51
50
|
|
lets_plot/plot/plot.py
CHANGED
|
@@ -6,10 +6,10 @@ import numbers
|
|
|
6
6
|
|
|
7
7
|
from lets_plot._global_settings import has_global_value, get_global_val, MAX_WIDTH, MAX_HEIGHT
|
|
8
8
|
from lets_plot.geo_data_internals.utils import is_geocoder
|
|
9
|
+
from lets_plot.plot._global_theme import _get_global_theme
|
|
9
10
|
from lets_plot.plot.core import FeatureSpec
|
|
10
11
|
from lets_plot.plot.core import PlotSpec
|
|
11
|
-
from lets_plot.plot.util import as_annotated_data
|
|
12
|
-
from lets_plot.plot._global_theme import _get_global_theme
|
|
12
|
+
from lets_plot.plot.util import as_annotated_data, key_int2str
|
|
13
13
|
|
|
14
14
|
__all__ = ['ggplot', 'ggsize', 'GGBunch']
|
|
15
15
|
|
|
@@ -83,6 +83,8 @@ def ggplot(data=None, mapping=None):
|
|
|
83
83
|
if is_geocoder(data):
|
|
84
84
|
data = data.get_geocodes()
|
|
85
85
|
|
|
86
|
+
data = key_int2str(data)
|
|
87
|
+
|
|
86
88
|
data, mapping, data_meta = as_annotated_data(data, mapping)
|
|
87
89
|
|
|
88
90
|
plot_spec = PlotSpec(data, mapping, scales=[], layers=[], **data_meta)
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Copyright (c) 2024. JetBrains s.r.o.
|
|
2
|
+
# Use of this source code is governed by the MIT license that can be found in the LICENSE file.
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
from .scale import _is_color_scale
|
|
10
|
+
from .scale import scale_gradientn
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import matplotlib
|
|
14
|
+
except ImportError:
|
|
15
|
+
matplotlib = None
|
|
16
|
+
|
|
17
|
+
__all__ = ['scale_cmapmpl',
|
|
18
|
+
'scale_fill_cmapmpl',
|
|
19
|
+
'scale_color_cmapmpl'
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _cmapmpl_to_hex(cmap) -> List[str]:
|
|
24
|
+
"""
|
|
25
|
+
Convert matplotlib colormap to list of hex colors.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
cmap: str or matplotlib colormap object
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
List of hex color strings.
|
|
34
|
+
"""
|
|
35
|
+
if matplotlib is None:
|
|
36
|
+
raise ImportError('matplotlib is not available. Please install it first.')
|
|
37
|
+
|
|
38
|
+
if isinstance(cmap, str):
|
|
39
|
+
cmap = matplotlib.colormaps[cmap]
|
|
40
|
+
if cmap is None:
|
|
41
|
+
raise ValueError(f"Unknown colormap: '{cmap}'")
|
|
42
|
+
|
|
43
|
+
if isinstance(cmap, matplotlib.colors.ListedColormap):
|
|
44
|
+
# colors from a discrete colormap (like "Dark2")
|
|
45
|
+
colors = cmap.colors
|
|
46
|
+
else:
|
|
47
|
+
# colors from a continuous colormap (like "plasma")
|
|
48
|
+
colors = cmap(range(64))
|
|
49
|
+
|
|
50
|
+
return [matplotlib.colors.to_hex(c) for c in colors]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def scale_cmapmpl(aesthetic, *,
|
|
54
|
+
cmap,
|
|
55
|
+
name=None, breaks=None, labels=None, lablim=None,
|
|
56
|
+
limits=None, na_value=None, guide=None, trans=None, format=None):
|
|
57
|
+
"""
|
|
58
|
+
Create a scale for color-related aesthetic using matplotlib colormap.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
aesthetic : str or list
|
|
63
|
+
The name(s) of the aesthetic(s) that this scale works with.
|
|
64
|
+
Valid values are: 'color', 'fill', 'paint_a', 'paint_b', 'paint_c'.
|
|
65
|
+
cmap : str or matplotlib colormap object
|
|
66
|
+
The name of colormap or the colormap object to use.
|
|
67
|
+
name : str
|
|
68
|
+
The name of the scale - used as the axis label or the legend title.
|
|
69
|
+
If None, the default, the name of the scale
|
|
70
|
+
is taken from the first mapping used for that aesthetic.
|
|
71
|
+
breaks : list or dict
|
|
72
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
73
|
+
labels : list of str or dict
|
|
74
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
75
|
+
lablim : int, default=None
|
|
76
|
+
The maximum label length (in characters) before trimming is applied.
|
|
77
|
+
limits : list
|
|
78
|
+
A numeric vector of length two providing limits of the scale.
|
|
79
|
+
na_value
|
|
80
|
+
Missing values will be replaced with this value.
|
|
81
|
+
guide
|
|
82
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
83
|
+
or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
|
|
84
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
85
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
86
|
+
Name of built-in transformation.
|
|
87
|
+
format : str
|
|
88
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
89
|
+
|
|
90
|
+
- '.2f' -> '12.45'
|
|
91
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
92
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
93
|
+
|
|
94
|
+
For more info see https://lets-plot.org/python/pages/formats.html.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
`FeatureSpec`
|
|
99
|
+
The scale specification.
|
|
100
|
+
|
|
101
|
+
Notes
|
|
102
|
+
-----
|
|
103
|
+
This function requires matplotlib to be installed.
|
|
104
|
+
|
|
105
|
+
Examples
|
|
106
|
+
--------
|
|
107
|
+
|
|
108
|
+
.. jupyter-execute::
|
|
109
|
+
:linenos:
|
|
110
|
+
:emphasize-lines: 6
|
|
111
|
+
|
|
112
|
+
from lets_plot import *
|
|
113
|
+
LetsPlot.setup_html()
|
|
114
|
+
x = list(range(50))
|
|
115
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
116
|
+
geom_tile(aes(color='x', fill='x')) + \\
|
|
117
|
+
scale_cmapmpl(aesthetic=['color', 'fill'], cmap='plasma', breaks=[5, 25, 45]) + \\
|
|
118
|
+
coord_cartesian() + \\
|
|
119
|
+
ggsize(600, 200)
|
|
120
|
+
|
|
121
|
+
"""
|
|
122
|
+
if not _is_color_scale(aesthetic):
|
|
123
|
+
raise ValueError(
|
|
124
|
+
f"Invalid aesthetic: {aesthetic}. Expected one of: 'color', 'fill', 'paint_a', 'paint_b', 'paint_c'")
|
|
125
|
+
|
|
126
|
+
return scale_gradientn(aesthetic,
|
|
127
|
+
colors=_cmapmpl_to_hex(cmap),
|
|
128
|
+
name=name,
|
|
129
|
+
breaks=breaks,
|
|
130
|
+
labels=labels,
|
|
131
|
+
lablim=lablim,
|
|
132
|
+
limits=limits,
|
|
133
|
+
na_value=na_value,
|
|
134
|
+
guide=guide,
|
|
135
|
+
trans=trans,
|
|
136
|
+
format=format
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def scale_fill_cmapmpl(cmap, *,
|
|
141
|
+
name=None, breaks=None, labels=None, lablim=None,
|
|
142
|
+
limits=None, na_value=None, guide=None, trans=None, format=None):
|
|
143
|
+
"""
|
|
144
|
+
Create a scale for the 'fill' aesthetic using matplotlib colormap.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
cmap : str or matplotlib colormap object
|
|
149
|
+
The name of colormap or the colormap object to use.
|
|
150
|
+
name : str
|
|
151
|
+
The name of the scale - used as the axis label or the legend title.
|
|
152
|
+
If None, the default, the name of the scale
|
|
153
|
+
is taken from the first mapping used for that aesthetic.
|
|
154
|
+
breaks : list or dict
|
|
155
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
156
|
+
labels : list of str or dict
|
|
157
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
158
|
+
lablim : int, default=None
|
|
159
|
+
The maximum label length (in characters) before trimming is applied.
|
|
160
|
+
limits : list
|
|
161
|
+
A numeric vector of length two providing limits of the scale.
|
|
162
|
+
na_value
|
|
163
|
+
Missing values will be replaced with this value.
|
|
164
|
+
guide
|
|
165
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
166
|
+
or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
|
|
167
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
168
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
169
|
+
Name of built-in transformation.
|
|
170
|
+
format : str
|
|
171
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
172
|
+
|
|
173
|
+
- '.2f' -> '12.45'
|
|
174
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
175
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
176
|
+
|
|
177
|
+
For more info see https://lets-plot.org/python/pages/formats.html.
|
|
178
|
+
|
|
179
|
+
Returns
|
|
180
|
+
-------
|
|
181
|
+
`FeatureSpec`
|
|
182
|
+
The scale specification.
|
|
183
|
+
|
|
184
|
+
Notes
|
|
185
|
+
-----
|
|
186
|
+
This function requires matplotlib to be installed.
|
|
187
|
+
|
|
188
|
+
Examples
|
|
189
|
+
--------
|
|
190
|
+
|
|
191
|
+
.. jupyter-execute::
|
|
192
|
+
:linenos:
|
|
193
|
+
:emphasize-lines: 6
|
|
194
|
+
|
|
195
|
+
from lets_plot import *
|
|
196
|
+
LetsPlot.setup_html()
|
|
197
|
+
x = list(range(50))
|
|
198
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
199
|
+
geom_tile(aes(fill='x')) + \\
|
|
200
|
+
scale_fill_cmapmpl('plasma', breaks=[5, 25, 45]) + \\
|
|
201
|
+
coord_cartesian() + \\
|
|
202
|
+
ggsize(600, 200)
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
return scale_cmapmpl('fill',
|
|
207
|
+
cmap=cmap,
|
|
208
|
+
name=name,
|
|
209
|
+
breaks=breaks,
|
|
210
|
+
labels=labels,
|
|
211
|
+
lablim=lablim,
|
|
212
|
+
limits=limits,
|
|
213
|
+
na_value=na_value,
|
|
214
|
+
guide=guide,
|
|
215
|
+
trans=trans,
|
|
216
|
+
format=format)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def scale_color_cmapmpl(cmap, *,
|
|
220
|
+
name=None, breaks=None, labels=None, lablim=None, limits=None,
|
|
221
|
+
na_value=None, guide=None, trans=None, format=None):
|
|
222
|
+
"""
|
|
223
|
+
Create a scale for the 'color' aesthetic using matplotlib colormap.
|
|
224
|
+
|
|
225
|
+
Parameters
|
|
226
|
+
----------
|
|
227
|
+
cmap : str or matplotlib colormap object
|
|
228
|
+
The name of colormap or the colormap object to use.
|
|
229
|
+
name : str
|
|
230
|
+
The name of the scale - used as the axis label or the legend title.
|
|
231
|
+
If None, the default, the name of the scale
|
|
232
|
+
is taken from the first mapping used for that aesthetic.
|
|
233
|
+
breaks : list or dict
|
|
234
|
+
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
|
|
235
|
+
labels : list of str or dict
|
|
236
|
+
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
|
|
237
|
+
lablim : int, default=None
|
|
238
|
+
The maximum label length (in characters) before trimming is applied.
|
|
239
|
+
limits : list
|
|
240
|
+
A numeric vector of length two providing limits of the scale.
|
|
241
|
+
na_value
|
|
242
|
+
Missing values will be replaced with this value.
|
|
243
|
+
guide
|
|
244
|
+
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
|
|
245
|
+
or a call to a guide function (`guide_colorbar()`, `guide_legend()`)
|
|
246
|
+
specifying additional arguments. 'none' will hide the guide.
|
|
247
|
+
trans : {'identity', 'log10', 'log2', 'symlog', 'sqrt', 'reverse'}
|
|
248
|
+
Name of built-in transformation.
|
|
249
|
+
format : str
|
|
250
|
+
Define the format for labels on the scale. The syntax resembles Python's:
|
|
251
|
+
|
|
252
|
+
- '.2f' -> '12.45'
|
|
253
|
+
- 'Num {}' -> 'Num 12.456789'
|
|
254
|
+
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
|
|
255
|
+
|
|
256
|
+
For more info see https://lets-plot.org/python/pages/formats.html.
|
|
257
|
+
|
|
258
|
+
Returns
|
|
259
|
+
-------
|
|
260
|
+
`FeatureSpec`
|
|
261
|
+
The scale specification.
|
|
262
|
+
|
|
263
|
+
Notes
|
|
264
|
+
-----
|
|
265
|
+
This function requires matplotlib to be installed.
|
|
266
|
+
|
|
267
|
+
Examples
|
|
268
|
+
--------
|
|
269
|
+
|
|
270
|
+
.. jupyter-execute::
|
|
271
|
+
:linenos:
|
|
272
|
+
:emphasize-lines: 6
|
|
273
|
+
|
|
274
|
+
from lets_plot import *
|
|
275
|
+
LetsPlot.setup_html()
|
|
276
|
+
x = list(range(50))
|
|
277
|
+
ggplot({'x': x}, aes(x='x')) + \\
|
|
278
|
+
geom_tile(aes(color='x'), size=2) + \\
|
|
279
|
+
scale_color_cmapmpl('plasma', breaks=[5, 25, 45]) + \\
|
|
280
|
+
coord_cartesian() + \\
|
|
281
|
+
ggsize(600, 200)
|
|
282
|
+
|
|
283
|
+
"""
|
|
284
|
+
|
|
285
|
+
return scale_cmapmpl('color',
|
|
286
|
+
cmap=cmap,
|
|
287
|
+
name=name,
|
|
288
|
+
breaks=breaks,
|
|
289
|
+
labels=labels,
|
|
290
|
+
lablim=lablim,
|
|
291
|
+
limits=limits,
|
|
292
|
+
na_value=na_value,
|
|
293
|
+
guide=guide,
|
|
294
|
+
trans=trans,
|
|
295
|
+
format=format)
|