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
lets_plot/plot/plot.py ADDED
@@ -0,0 +1,245 @@
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
+ import numbers
6
+
7
+ from lets_plot._global_settings import has_global_value, get_global_val, MAX_WIDTH, MAX_HEIGHT
8
+ from lets_plot.geo_data_internals.utils import is_geocoder
9
+ from lets_plot.plot._global_theme import _get_global_theme
10
+ from lets_plot.plot.core import FeatureSpec
11
+ from lets_plot.plot.core import PlotSpec
12
+ from lets_plot.plot.util import as_annotated_data, key_int2str
13
+
14
+ __all__ = ['ggplot', 'ggsize', 'GGBunch']
15
+
16
+
17
+ def ggplot(data=None, mapping=None):
18
+ """
19
+ Create a new ggplot plot.
20
+
21
+ Parameters
22
+ ----------
23
+ data : dict or Pandas or Polars ``DataFrame``
24
+ Default dataset to use for the plot. If not specified,
25
+ must be supplied in each layer added to the plot.
26
+ mapping : ``FeatureSpec``
27
+ Default list of aesthetic mappings to use for the plot.
28
+ If not specified, must be supplied in each layer added to the plot.
29
+
30
+ Returns
31
+ -------
32
+ ``PlotSpec``
33
+ Plot specification.
34
+
35
+ Notes
36
+ -----
37
+ ``ggplot()`` initializes a ggplot object.
38
+ It can be used to declare the input data frame for a graphic and
39
+ to specify the set of plot aesthetics intended to be common
40
+ throughout all subsequent layers unless specifically overridden.
41
+
42
+ ``ggplot()`` is typically used to construct a plot incrementally,
43
+ using the + operator to add layers to the existing ggplot object.
44
+ This is advantageous in that the code is explicit about which layers
45
+ are added and the order in which they are added. For complex graphics
46
+ with multiple layers, initialization with ``ggplot()`` is recommended.
47
+
48
+ There are three common ways to invoke ggplot (see examples below):
49
+
50
+ - ``ggplot(data, aes(x, y))``: This method is recommended if all layers use the same data and the same set of aesthetics, although this method can also be used to add a layer using data from another data frame.
51
+ - ``ggplot(data)``: This method specifies the default data frame to use for the plot, but no aesthetics are defined up front. This is useful when one data frame is used predominantly as layers are added, but the aesthetics may vary from one layer to another.
52
+ - ``ggplot()``: This method initializes a skeleton ggplot object which is fleshed out as layers are added. This method is useful when multiple data frames are used to produce different layers, as is often the case in complex graphics.
53
+
54
+ ``ggplot()`` with no layers defined will produce an error message:
55
+ "No layers in plot".
56
+
57
+ Examples
58
+ --------
59
+ .. jupyter-execute::
60
+ :linenos:
61
+ :emphasize-lines: 11, 13, 15
62
+
63
+ import numpy as np
64
+ from lets_plot import *
65
+ LetsPlot.setup_html()
66
+ np.random.seed(42)
67
+ n = 100
68
+ x = np.random.uniform(-1, 1, size=n)
69
+ y = np.random.normal(size=n)
70
+ data = {'x': x, 'y': 25 * x ** 2 + y}
71
+ # three ways to invoke ggplot, producing the same output:
72
+ # (1)
73
+ ggplot(data, aes(x='x', y='y')) + geom_point()
74
+ # (2)
75
+ ggplot(data) + geom_point(aes(x='x', y='y'))
76
+ # (3)
77
+ ggplot() + geom_point(aes(x='x', y='y'), data=data)
78
+
79
+ """
80
+ if isinstance(data, FeatureSpec):
81
+ raise ValueError("Object {!r} is not acceptable as 'data' argument in ggplot()".format(data.kind))
82
+
83
+ if is_geocoder(data):
84
+ data = data.get_geocodes()
85
+
86
+ data = key_int2str(data)
87
+
88
+ data, mapping, data_meta = as_annotated_data(data, mapping)
89
+
90
+ plot_spec = PlotSpec(data, mapping, scales=[], layers=[], **data_meta)
91
+
92
+ if _get_global_theme() is not None:
93
+ plot_spec += _get_global_theme()
94
+
95
+ return plot_spec
96
+
97
+
98
+ # noinspection SpellCheckingInspection
99
+ def ggsize(width, height):
100
+ """
101
+ Specify overall size of plot.
102
+
103
+ Parameters
104
+ ----------
105
+ width : int
106
+ Width of plot in px.
107
+ height : int
108
+ Height of plot in px.
109
+
110
+ Returns
111
+ -------
112
+ ``FeatureSpec``
113
+ Plot size specification.
114
+
115
+ Examples
116
+ --------
117
+ .. jupyter-execute::
118
+ :linenos:
119
+ :emphasize-lines: 8
120
+
121
+ import numpy as np
122
+ from lets_plot import *
123
+ LetsPlot.setup_html()
124
+ np.random.seed(42)
125
+ x = np.arange(50)
126
+ y = np.random.normal(size=50)
127
+ data = {'x': x, 'y': y}
128
+ ggplot(data) + geom_line(aes('x', 'y')) + ggsize(400, 150)
129
+
130
+ """
131
+ assert isinstance(width, numbers.Number), "'width' must be numeric"
132
+ assert isinstance(height, numbers.Number), "'height' must be numeric"
133
+
134
+ max_width = get_global_val(MAX_WIDTH) if has_global_value(MAX_WIDTH) else 10_000
135
+ max_height = get_global_val(MAX_HEIGHT) if has_global_value(MAX_HEIGHT) else 10_000
136
+
137
+ assert width <= max_width, "'width' must be less than or equal to " + str(max_width)
138
+ assert height <= max_height, "'height' must be less than or equal to " + str(max_height)
139
+
140
+ return FeatureSpec('ggsize', name=None, width=width, height=height)
141
+
142
+
143
+ class GGBunch(FeatureSpec):
144
+ """
145
+ Class ``GGBunch`` is deprecated and will be removed in future releases.
146
+ Please, use function `ggbunch() <https://lets-plot.org/python/pages/api/lets_plot.ggbunch.html>`__
147
+ to combine several plots into a single figure with custom layout.
148
+
149
+ Collection of plots created by ggplot function.
150
+ Use method ``add_plot()`` to add plot to 'bunch'.
151
+ Each plot can have arbitrary location and size.
152
+ Use ``show()`` to draw all plots in bunch.
153
+
154
+ Examples
155
+ --------
156
+ .. jupyter-execute::
157
+ :linenos:
158
+ :emphasize-lines: 10-14
159
+
160
+ import numpy as np
161
+ from lets_plot import *
162
+ LetsPlot.setup_html()
163
+ np.random.seed(42)
164
+ n = 100
165
+ x = np.arange(n)
166
+ y = np.random.normal(size=n)
167
+ w, h = 200, 150
168
+ p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h)
169
+ bunch = GGBunch()
170
+ bunch.add_plot(p + geom_point(), 0, 0)
171
+ bunch.add_plot(p + geom_histogram(bins=3), w, 0)
172
+ bunch.add_plot(p + geom_line(), 0, h, 2*w, h)
173
+ bunch.show()
174
+
175
+ """
176
+
177
+ def __init__(self):
178
+ """
179
+ Initialize self.
180
+ """
181
+ super().__init__('ggbunch', None)
182
+ self.items = []
183
+ print("\n(!) WARN: class GGBunch is deprecated and will be removed in future releases.\n\n"
184
+ " Please, use function ggbunch() to combine several plots into\n"
185
+ " a single figure with custom layout.\n")
186
+
187
+
188
+ def add_plot(self, plot_spec: PlotSpec, x, y, width=None, height=None):
189
+ """
190
+ Add plot to 'bunch'.
191
+
192
+ Parameters
193
+ ----------
194
+ plot_spec
195
+ Plot specification created by ``ggplot()`` function.
196
+ x : int
197
+ x-coordinate of plot origin in px.
198
+ y : int
199
+ y-coordinate of plot origin in px.
200
+ width : int
201
+ Width of plot in px.
202
+ height : int
203
+ Height of plot in px.
204
+
205
+ """
206
+ if width and not height:
207
+ raise TypeError('height argument is required')
208
+ if height and not width:
209
+ raise TypeError('width argument is required')
210
+
211
+ assert isinstance(x, numbers.Number), "'x' must be numeric"
212
+ assert isinstance(y, numbers.Number), "'y' must be numeric"
213
+ if width:
214
+ assert isinstance(width, numbers.Number), "'width' must be numeric"
215
+ if height:
216
+ assert isinstance(height, numbers.Number), "'height' must be numeric"
217
+
218
+ self.items.append(dict(feature_spec=plot_spec, x=x, y=y, width=width, height=height))
219
+
220
+ def as_dict(self):
221
+ d = super().as_dict()
222
+ d['kind'] = self.kind
223
+
224
+ def item_as_dict(item):
225
+ result = dict((k, v) for k, v in item.items() if k != 'feature_spec')
226
+ result['feature_spec'] = item['feature_spec'].as_dict()
227
+ return result
228
+
229
+ d['items'] = [item_as_dict(item) for item in self.items]
230
+ return d
231
+
232
+ def _repr_html_(self):
233
+ """
234
+ Special method discovered and invoked by IPython.display.display.
235
+ """
236
+ from ..frontend_context._configuration import _as_html
237
+ return _as_html(self.as_dict())
238
+
239
+ def show(self):
240
+ """
241
+ Draw all plots currently in this 'bunch'.
242
+ """
243
+ from ..frontend_context._configuration import _display_plot
244
+ _display_plot(self)
245
+
lets_plot/plot/pos.py ADDED
@@ -0,0 +1,344 @@
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
6
+
7
+ #
8
+ # Position Adjustments
9
+ #
10
+ __all__ = ['position_dodge', 'position_dodgev', 'position_jitter', 'position_nudge', 'position_jitterdodge',
11
+ 'position_stack', 'position_fill']
12
+
13
+
14
+ def position_dodge(width=None):
15
+ """
16
+ Adjust position by dodging overlaps to the side.
17
+
18
+ Parameters
19
+ ----------
20
+ width : float
21
+ Dodging width, when different to the width of the individual elements.
22
+ This is useful when you want to align narrow geoms with wider geoms.
23
+ The value of width is relative and typically ranges between 0 and 1.
24
+ Values that are greater than 1 lead to overlapping of the objects.
25
+ The default value is taken from the width aesthetics of the data point.
26
+
27
+ Returns
28
+ -------
29
+ ``FeatureSpec``
30
+ Geom object position specification.
31
+
32
+ Notes
33
+ -----
34
+ Adjust position by dodging overlaps to the side.
35
+
36
+ Examples
37
+ --------
38
+ .. jupyter-execute::
39
+ :linenos:
40
+ :emphasize-lines: 10
41
+
42
+ import numpy as np
43
+ from lets_plot import *
44
+ LetsPlot.setup_html()
45
+ n = 100
46
+ np.random.seed(42)
47
+ x = np.random.randint(5, size=n)
48
+ c = np.random.choice(['a', 'b', 'c'], size=n)
49
+ ggplot({'x': x, 'c': c}, aes(x='x')) + \\
50
+ geom_bar(aes(fill='c'), width=.4, \\
51
+ position=position_dodge(width=.6))
52
+
53
+ """
54
+ return _pos('dodge', width=width)
55
+
56
+
57
+ def position_dodgev(height=None):
58
+ """
59
+ Function ``position_dodgev()`` is deprecated and will be removed in future releases.
60
+
61
+ """
62
+ print("WARN: The function position_dodgev() is deprecated and will be removed in future releases.")
63
+
64
+ return _pos('dodgev', height=height)
65
+
66
+
67
+ def position_jitter(width=None, height=None, seed=None):
68
+ """
69
+ Adjust position by assigning random noise to points. Better for discrete values.
70
+
71
+ Parameters
72
+ ----------
73
+ width : float, default=.4
74
+ Jittering width.
75
+ The value of width is relative and typically ranges between 0 and 0.5.
76
+ Values that are greater than 0.5 lead to overlapping of the points.
77
+ height : float, default=.4
78
+ Jittering height.
79
+ The value of height is relative and typically ranges between 0 and 0.5.
80
+ Values that are greater than 0.5 lead to overlapping of the points.
81
+ seed : int
82
+ A random seed to make the jitter reproducible.
83
+ If None (the default value), the seed is initialised with a random value.
84
+
85
+ Returns
86
+ -------
87
+ ``FeatureSpec``
88
+ Geom object position specification.
89
+
90
+ Notes
91
+ -----
92
+ Adjust position by dodging overlaps to the side.
93
+
94
+ Examples
95
+ --------
96
+ .. jupyter-execute::
97
+ :linenos:
98
+ :emphasize-lines: 12
99
+
100
+ import numpy as np
101
+ from lets_plot import *
102
+ LetsPlot.setup_html()
103
+ n = 100
104
+ np.random.seed(42)
105
+ x = np.random.randint(4, size=n)
106
+ y = np.random.randint(3, size=n)
107
+ c = np.char.add(x.astype(str), y.astype(str))
108
+ ggplot({'x': x, 'y': y, 'c': c}, aes('x', 'y')) + \\
109
+ geom_point(aes(fill='c'), show_legend=False, \\
110
+ size=8, alpha=.5, shape=21, color='black', \\
111
+ position=position_jitter(width=.2, height=.2, seed=42))
112
+
113
+ """
114
+ return _pos('jitter', width=width, height=height, seed=seed)
115
+
116
+
117
+ def position_nudge(x=None, y=None, unit=None):
118
+ """
119
+ Adjust position by nudging a given offset.
120
+
121
+ Parameters
122
+ ----------
123
+ x : float, default=0.0
124
+ Nudging width.
125
+ y : float, default=0.0
126
+ Nudging height.
127
+ unit : {'identity', 'size', 'px'}, default='identity'
128
+ Units for x and y nudging.
129
+ Possible values:
130
+
131
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
132
+ - 'size': a unit of 1 corresponds to the diameter of a point with ``size=1``;
133
+ - 'px': the unit is measured in screen pixels.
134
+
135
+ Returns
136
+ -------
137
+ ``FeatureSpec``
138
+ Geom object position specification.
139
+
140
+ Notes
141
+ -----
142
+ Adjust position by dodging overlaps to the side.
143
+
144
+ Examples
145
+ --------
146
+ .. jupyter-execute::
147
+ :linenos:
148
+ :emphasize-lines: 11
149
+
150
+ import numpy as np
151
+ from lets_plot import *
152
+ LetsPlot.setup_html()
153
+ n = 5
154
+ np.random.seed(42)
155
+ x = np.random.uniform(size=n)
156
+ y = np.random.uniform(size=n)
157
+ t = np.random.choice(list('abcdefghijk'), size=n)
158
+ ggplot({'x': x, 'y': y, 't': t}, aes('x', 'y')) + \\
159
+ geom_point(size=5, shape=21, color='black', fill='red') + \\
160
+ geom_text(aes(label='t'), position=position_nudge(y=.05, unit='identity'))
161
+
162
+ """
163
+ return _pos('nudge', x=x, y=y, unit=unit)
164
+
165
+
166
+ def position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None, seed=None):
167
+ """
168
+ This is primarily used for aligning points generated through `geom_point() <https://lets-plot.org/python/pages/api/lets_plot.geom_point.html>`__
169
+ with dodged boxplots (e.g., a `geom_boxplot() <https://lets-plot.org/python/pages/api/lets_plot.geom_boxplot.html>`__ with a fill aesthetic supplied).
170
+
171
+ Parameters
172
+ ----------
173
+ dodge_width : float
174
+ Bin width.
175
+ The value of ``dodge_width`` is relative and typically ranges between 0 and 1.
176
+ Values that are greater than 1 lead to overlapping of the boxes.
177
+ The default value is taken from the width aesthetics of the data point.
178
+ jitter_width : float, default=.4
179
+ Jittering width.
180
+ The value of ``jitter_width`` is relative and typically ranges between 0 and 0.5.
181
+ Values that are greater than 0.5 lead to overlapping of the points.
182
+ jitter_height : float, default=.4
183
+ Jittering height.
184
+ The value of ``jitter_height`` is relative and typically ranges between 0 and 0.5.
185
+ Values that are greater than 0.5 lead to overlapping of the points.
186
+ seed : int
187
+ A random seed to make the jitter reproducible.
188
+ If None (the default value), the seed is initialised with a random value.
189
+
190
+ Returns
191
+ -------
192
+ ``FeatureSpec``
193
+ Geom object position specification.
194
+
195
+ Notes
196
+ -----
197
+ Adjust position by dodging overlaps to the side.
198
+
199
+ Examples
200
+ --------
201
+ .. jupyter-execute::
202
+ :linenos:
203
+ :emphasize-lines: 13
204
+
205
+ import numpy as np
206
+ from lets_plot import *
207
+ LetsPlot.setup_html()
208
+ n = 50
209
+ np.random.seed(42)
210
+ x = np.random.uniform(size=n)
211
+ c = np.random.choice(['a', 'b', 'c'], size=n)
212
+ ggplot({'x': x, 'c': c}) + \\
213
+ geom_crossbar(aes(x='c', y='x', color='c'), \\
214
+ stat='boxplot') + \\
215
+ geom_point(aes(x='c', y='x', color='c'), \\
216
+ size=4, shape=21, fill='white',
217
+ position=position_jitterdodge(seed=42))
218
+
219
+ """
220
+ return _pos('jitterdodge', dodge_width=dodge_width, jitter_width=jitter_width, jitter_height=jitter_height,
221
+ seed=seed)
222
+
223
+
224
+ def position_stack(vjust=None, mode=None):
225
+ """
226
+ Adjust position by stacking overlapping objects on top of each other.
227
+ Preferred for density-like geometries.
228
+
229
+ Parameters
230
+ ----------
231
+ vjust : float, default=1.0
232
+ Vertical adjustment for geoms that have a position (like points or lines),
233
+ not a dimension (like bars or areas).
234
+ Set to 0 to align with the bottom, 0.5 for the middle, and 1 for the top.
235
+ mode : {'groups', 'all'}, default='groups'
236
+ If 'groups', objects inside one group are positioned as in ``position='identity'``,
237
+ but each group is shifted to sum of heights of previous groups
238
+ (where height of a group is a maximum of it's y values).
239
+ If 'all', each object will be shifted.
240
+
241
+ Returns
242
+ -------
243
+ ``FeatureSpec``
244
+ Geom object position specification.
245
+
246
+ Notes
247
+ -----
248
+ Adjust position by stacking overlapping objects on top of each other.
249
+
250
+ Examples
251
+ --------
252
+ .. jupyter-execute::
253
+ :linenos:
254
+ :emphasize-lines: 12,18
255
+
256
+ from lets_plot import *
257
+ LetsPlot.setup_html()
258
+ data = {
259
+ 'x': [-2, -2, -2, 2, 2, 2],
260
+ 'y': [1, 2, 3, 1, 2, 3],
261
+ 'g': ["a", "b", "b", "a", "a", "b"],
262
+ }
263
+ gggrid([
264
+ ggplot(data, aes('x', 'y', fill='g')) + \\
265
+ geom_label(aes(label='y'), size=10,
266
+ color="white", show_legend=False,
267
+ position=position_stack(mode='groups')) + \\
268
+ scale_y_continuous(limits=[0, 6]) + \\
269
+ ggtitle("mode='groups'"),
270
+ ggplot(data, aes('x', 'y', fill='g')) + \\
271
+ geom_label(aes(label='y'), size=10,
272
+ color="white", show_legend=False,
273
+ position=position_stack(mode='all')) + \\
274
+ scale_y_continuous(limits=[0, 6]) + \\
275
+ ggtitle("mode='all'"),
276
+ ])
277
+
278
+ """
279
+ return _pos('stack', vjust=vjust, mode=mode)
280
+
281
+
282
+ def position_fill(vjust=None, mode=None):
283
+ """
284
+ Adjust position by stacking overlapping objects on top of each other
285
+ and standardise each stack to have constant height.
286
+
287
+ Parameters
288
+ ----------
289
+ vjust : float, default=1.0
290
+ Vertical adjustment for geoms that have a position (like points or lines),
291
+ not a dimension (like bars or areas).
292
+ Set to 0 to align with the bottom, 0.5 for the middle, and 1 for the top.
293
+ mode : {'groups', 'all'}, default='groups'
294
+ If 'groups', objects inside one group are positioned as in ``position='identity'``,
295
+ but each group is shifted to sum of heights of previous groups
296
+ (where height of a group is a maximum of it's y values).
297
+ If 'all', each object will be shifted.
298
+
299
+ Returns
300
+ -------
301
+ ``FeatureSpec``
302
+ Geom object position specification.
303
+
304
+ Notes
305
+ -----
306
+ Adjust position by stacking overlapping objects on top of each other
307
+ and standardise each stack to have constant height.
308
+
309
+ Examples
310
+ --------
311
+ .. jupyter-execute::
312
+ :linenos:
313
+ :emphasize-lines: 12,18
314
+
315
+ from lets_plot import *
316
+ LetsPlot.setup_html()
317
+ data = {
318
+ 'x': [1, 1, 1, 1, 1, 2, 2, 2],
319
+ 'y': [1, 2, 1, 3, 5, 1, 2, 2],
320
+ 'g': ["a", "a", "b", "b", "b", "a", "a", "b"],
321
+ }
322
+ gggrid([
323
+ ggplot(data, aes('x', 'y', fill='g')) + \\
324
+ geom_label(aes(label='y'), size=10,
325
+ color="white", show_legend=False,
326
+ position=position_fill(mode='groups')) + \\
327
+ coord_cartesian(ylim=[0, 1.1]) + \\
328
+ ggtitle("mode='groups'"),
329
+ ggplot(data, aes('x', 'y', fill='g')) + \\
330
+ geom_label(aes(label='y'), size=10,
331
+ color="white", show_legend=False,
332
+ position=position_fill(mode='all')) + \\
333
+ coord_cartesian(ylim=[0, 1.1]) + \\
334
+ ggtitle("mode='all'"),
335
+ ])
336
+
337
+ """
338
+ return _pos('fill', vjust=vjust, mode=mode)
339
+
340
+
341
+ def _pos(name, **other):
342
+ args = locals().copy()
343
+ args.pop('other')
344
+ return FeatureSpec('pos', **args, **other)