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,192 @@
1
+ #
2
+ # Copyright (c) 2023. 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 ._plot2d_common import _get_bin_params_2d, _get_geom2d_layer, _get_marginal_layers
6
+ from ..plot.core import DummySpec, aes
7
+ from ..plot.geom import geom_smooth
8
+ from ..plot.label import xlab, ylab
9
+ from ..plot.plot import ggplot
10
+
11
+ __all__ = ['joint_plot']
12
+
13
+ _GEOM_DEF = 'point'
14
+
15
+ _REG_LINE_METHOD = 'lm'
16
+ _REG_LINE_COLOR = "magenta"
17
+ _REG_LINE_LINETYPE = 'dashed'
18
+
19
+
20
+ def _get_marginal_def(geom_kind, color_by=None):
21
+ if geom_kind in ['density2d', 'density2df'] or color_by is not None:
22
+ return "dens:tr"
23
+ else:
24
+ return "hist:tr"
25
+
26
+
27
+ def _is_reg_line_needed(reg_line, geom_kind):
28
+ if reg_line is not None:
29
+ return reg_line
30
+ if geom_kind in ['point', 'pointdensity']:
31
+ return True
32
+ else:
33
+ return False
34
+
35
+
36
+ def joint_plot(data, x, y, *,
37
+ geom=None,
38
+ bins=None, binwidth=None,
39
+ color=None, size=None, alpha=None,
40
+ color_by=None,
41
+ show_legend=None,
42
+ reg_line=None,
43
+ se=None,
44
+ marginal=None):
45
+ """
46
+ Produce a joint plot that contains bivariate and univariate graphs at the same time.
47
+
48
+ Parameters
49
+ ----------
50
+ data : dict or Pandas or Polars ``DataFrame``
51
+ The data to be displayed.
52
+ x, y : str
53
+ Names of a variables.
54
+ geom : {'point', 'tile', 'hex', 'density2d', 'density2df', 'pointdensity'}, default='point'
55
+ The geometric object to use to display the data.
56
+ bins : int or list of int
57
+ Number of bins in both directions, vertical and horizontal. Overridden by ``binwidth``.
58
+ If only one value given - interpret it as list of two equal values.
59
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
60
+ binwidth : float or list of float
61
+ The width of the bins in both directions, vertical and horizontal.
62
+ Overrides ``bins``. The default is to use bin widths that cover the entire range of the data.
63
+ If only one value given - interpret it as list of two equal values.
64
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
65
+ color : str
66
+ Color of the geometry.
67
+ For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
68
+ size : float
69
+ Size of the geometry.
70
+ alpha : float
71
+ Transparency level of the geometry. Accept values between 0 and 1.
72
+ color_by : str
73
+ Name of grouping variable.
74
+ show_legend : bool, default=True
75
+ False - do not show legend for the main layer.
76
+ reg_line : bool
77
+ True - show the line of linear regression.
78
+ se : bool, default=True
79
+ Display confidence interval around regression line.
80
+ marginal : str
81
+ Description of marginal layers packed to string value.
82
+ Different marginals are separated by the ',' char.
83
+ Parameters of a marginal are separated by the ':' char.
84
+ First parameter of a marginal is a geometry name.
85
+ Possible values: 'dens'/'density', 'hist'/'histogram', 'box'/'boxplot'.
86
+ Second parameter is a string specifying which sides of the plot the marginal layer will appear on.
87
+ Possible values: 't' (top), 'b' (bottom), 'l' (left), 'r' (right).
88
+ Third parameter (optional) is size of marginal.
89
+ To suppress marginals use ``marginal='none'``.
90
+ Examples:
91
+ "hist:tr:0.3",
92
+ "dens:tr,hist:bl",
93
+ "box:tr:.05, hist:bl, dens:bl".
94
+
95
+ Returns
96
+ -------
97
+ ``PlotSpec``
98
+ Plot object specification.
99
+
100
+ Notes
101
+ -----
102
+ To hide axis tooltips, set 'blank' or the result of `element_blank() <https://lets-plot.org/python/pages/api/lets_plot.element_blank.html>`__
103
+ to the ``axis_tooltip``, ``axis_tooltip_x`` or ``axis_tooltip_y`` parameter of the `theme() <https://lets-plot.org/python/pages/api/lets_plot.theme.html>`__.
104
+
105
+ Examples
106
+ --------
107
+ .. jupyter-execute::
108
+ :linenos:
109
+ :emphasize-lines: 11
110
+
111
+ import numpy as np
112
+ from lets_plot import *
113
+ from lets_plot.bistro.joint import *
114
+ LetsPlot.setup_html()
115
+ n = 100
116
+ np.random.seed(42)
117
+ data = {
118
+ 'x': np.random.normal(size=n),
119
+ 'y': np.random.normal(size=n)
120
+ }
121
+ joint_plot(data, 'x', 'y')
122
+
123
+ |
124
+
125
+ .. jupyter-execute::
126
+ :linenos:
127
+ :emphasize-lines: 11-13
128
+
129
+ import numpy as np
130
+ from lets_plot import *
131
+ from lets_plot.bistro.joint import *
132
+ LetsPlot.setup_html()
133
+ n = 500
134
+ np.random.seed(42)
135
+ data = {
136
+ 'x': np.random.normal(size=n),
137
+ 'y': np.random.normal(size=n)
138
+ }
139
+ joint_plot(data, 'x', 'y', geom='tile', \\
140
+ binwidth=[.5, .5], color="black", \\
141
+ marginal="hist:tr,box:bl") + \\
142
+ theme_minimal()
143
+
144
+ |
145
+
146
+ .. jupyter-execute::
147
+ :linenos:
148
+ :emphasize-lines: 12
149
+
150
+ import numpy as np
151
+ from lets_plot import *
152
+ from lets_plot.bistro.joint import *
153
+ LetsPlot.setup_html()
154
+ n = 500
155
+ np.random.seed(42)
156
+ data = {
157
+ 'x': np.concatenate((np.random.normal(loc=-1, size=n), np.random.normal(loc=2, size=n))),
158
+ 'y': np.concatenate((np.random.normal(loc=-.5, size=n), np.random.normal(loc=1.5, size=n))),
159
+ 'g': ["A"] * n + ["B"] * n
160
+ }
161
+ joint_plot(data, 'x', 'y', geom='density2df', color_by='g', alpha=.75)
162
+
163
+ """
164
+ # prepare parameters
165
+ geom_kind = geom or _GEOM_DEF
166
+ binwidth2d, bins2d = _get_bin_params_2d(data[x], data[y], binwidth, bins)
167
+ # prepare mapping
168
+ mapping_dict = {'x': x, 'y': y}
169
+ if color_by is not None:
170
+ mapping_dict['color'] = color_by
171
+ mapping_dict['fill'] = color_by
172
+ # prepare layers
173
+ layers = DummySpec()
174
+ # main layer
175
+ main_layer = _get_geom2d_layer(geom_kind, binwidth2d, bins2d, color, color_by, size, alpha, show_legend)
176
+ if main_layer is not None:
177
+ layers += main_layer
178
+ # smooth layer
179
+ if _is_reg_line_needed(reg_line, geom_kind):
180
+ layers += geom_smooth(
181
+ aes(group=color_by),
182
+ method=_REG_LINE_METHOD, se=se,
183
+ color=_REG_LINE_COLOR, linetype=_REG_LINE_LINETYPE
184
+ )
185
+ # marginal layers
186
+ if len(data[x]) == 0:
187
+ marginal = 'none'
188
+ defined_marginal = marginal or _get_marginal_def(geom_kind, color_by)
189
+ if defined_marginal != 'none':
190
+ layers += _get_marginal_layers(defined_marginal, binwidth2d, bins2d, color, color_by, show_legend)
191
+
192
+ return ggplot(data, aes(**mapping_dict)) + layers + xlab(x) + ylab(y)
lets_plot/bistro/qq.py ADDED
@@ -0,0 +1,207 @@
1
+ # Copyright (c) 2022. 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
+ from lets_plot.plot.core import PlotSpec
5
+
6
+ __all__ = ['qq_plot']
7
+
8
+
9
+ def qq_plot(data=None, sample=None, *, x=None, y=None,
10
+ distribution=None, dparams=None, quantiles=None,
11
+ group=None,
12
+ show_legend=None,
13
+ marginal=None,
14
+ color=None, fill=None, alpha=None, size=None, shape=None,
15
+ line_color=None, line_size=None, linetype=None) -> PlotSpec:
16
+ """
17
+ Produce a Q-Q plot (quantile-quantile plot).
18
+
19
+ Supply the ``sample`` parameter to compare distribution of observations with a theoretical distribution
20
+ ('normal' or as otherwise specified by the ``distribution`` parameter).
21
+
22
+ Alternatively, supply ``x`` and ``y`` parameters to compare the distribution of ``x`` with the distribution of ``y``.
23
+
24
+ Parameters
25
+ ----------
26
+ data : dict or Pandas or Polars ``DataFrame``
27
+ The data to be displayed.
28
+ sample : str
29
+ Name of variable specifying a vector of observations used for computing of "sample quantiles".
30
+ Use this parameter to produce a "sample vs. theoretical" Q-Q plot.
31
+ x, y : str
32
+ Names of variables specifying two vectors of observations used for computing of
33
+ x and y "sample quantiles".
34
+ Use these two parameters to produce a "sample X vs. sample Y" Q-Q plot.
35
+ distribution : {'norm', 'uniform', 't', 'gamma', 'exp', 'chi2'}, default='norm'
36
+ Distribution function to use. Could be specified if ``sample`` is.
37
+ dparams : list
38
+ Additional parameters (of float type) passed on to distribution function.
39
+ Could be specified if ``sample`` is.
40
+ If ``distribution`` is ``'norm'`` then ``dparams`` is a pair [mean, std] (=[0.0, 1.0] by default).
41
+ If ``distribution`` is ``'uniform'`` then ``dparams`` is a pair [a, b] (=[0.0, 1.0] by default).
42
+ If ``distribution`` is ``'t'`` then ``dparams`` is an integer number [d] (=[1] by default).
43
+ If ``distribution`` is ``'gamma'`` then ``dparams`` is a pair [alpha, beta] (=[1.0, 1.0] by default).
44
+ If ``distribution`` is ``'exp'`` then ``dparams`` is a float number [lambda] (=[1.0] by default).
45
+ If ``distribution`` is ``'chi2'`` then ``dparams`` is an integer number [k] (=[1] by default).
46
+ quantiles : list, default=[0.25, 0.75]
47
+ Pair of quantiles to use when fitting the Q-Q line.
48
+ group : str
49
+ Grouping parameter.
50
+ If it is specified and color-parameters isn't then different groups will has different colors.
51
+ show_legend : bool, default=True
52
+ False - do not show legend.
53
+ marginal : str, default='dens:tr'
54
+ Description of marginal layers packed to string value.
55
+ Different marginals are separated by the ',' char.
56
+ Parameters of a marginal are separated by the ':' char.
57
+ First parameter of a marginal is a geometry name.
58
+ Possible values: 'dens'/'density', 'hist'/'histogram', 'box'/'boxplot'.
59
+ Second parameter is a string specifying which sides of the plot the marginal layer will appear on.
60
+ Possible values: 't' (top), 'b' (bottom), 'l' (left), 'r' (right).
61
+ Third parameter (optional) is size of marginal.
62
+ To suppress marginals use ``marginal='none'``.
63
+ Examples:
64
+ "hist:tr:0.3",
65
+ "dens:tr,hist:bl",
66
+ "box : tr : .05, dens : bl".
67
+ color : str
68
+ Color of a points.
69
+ For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
70
+ fill : str
71
+ Color to paint shape's inner points. Is applied only to the points of shapes having inner points.
72
+ For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
73
+ alpha : float, default=0.5
74
+ Transparency level of points. Accept values between 0 and 1.
75
+ size : float, default=3.0
76
+ Size of the points.
77
+ shape : int
78
+ Shape of the points, an integer from 0 to 25.
79
+ For more info see `Point Shapes <https://lets-plot.org/python/pages/aesthetics.html#point-shapes>`__.
80
+ line_color : str, default='#FF0000'
81
+ Color of the fitting line.
82
+ For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
83
+ line_size : float, default=0.75
84
+ Width of the fitting line.
85
+ linetype : int or str or list
86
+ Type of the fitting line.
87
+ Accept codes or names (0 = 'blank', 1 = 'solid', 2 = 'dashed', 3 = 'dotted', 4 = 'dotdash', 5 = 'longdash', 6 = 'twodash'),
88
+ a hex string (up to 8 digits for dash-gap lengths),
89
+ or a list pattern [offset, [dash, gap, ...]] / [dash, gap, ...].
90
+ For more info see `Line Types <https://lets-plot.org/python/pages/aesthetics.html#line-types>`__.
91
+
92
+ Returns
93
+ -------
94
+ ``PlotSpec``
95
+ Plot object specification.
96
+
97
+ Notes
98
+ -----
99
+ The Q-Q plot is used for comparing two probability distributions
100
+ (sample and theoretical or two sample) by plotting their quantiles against each other.
101
+
102
+ If the two distributions being compared are similar, the points in the Q-Q plot
103
+ will approximately lie on the straight line.
104
+
105
+ ----
106
+
107
+ To hide axis tooltips, set 'blank' or the result of `element_blank() <https://lets-plot.org/python/pages/api/lets_plot.element_blank.html>`__
108
+ to the ``axis_tooltip``, ``axis_tooltip_x`` or ``axis_tooltip_y`` parameter of the `theme() <https://lets-plot.org/python/pages/api/lets_plot.theme.html>`__.
109
+
110
+ Examples
111
+ --------
112
+ .. jupyter-execute::
113
+ :linenos:
114
+ :emphasize-lines: 8
115
+
116
+ import numpy as np
117
+ from lets_plot.bistro.qq import qq_plot
118
+ from lets_plot import *
119
+ LetsPlot.setup_html()
120
+ n = 100
121
+ np.random.seed(42)
122
+ x = np.random.normal(0, 1, n)
123
+ qq_plot(data={'x': x}, sample='x')
124
+
125
+ |
126
+
127
+ .. jupyter-execute::
128
+ :linenos:
129
+ :emphasize-lines: 8-10
130
+
131
+ import numpy as np
132
+ from lets_plot.bistro.qq import qq_plot
133
+ from lets_plot import *
134
+ LetsPlot.setup_html()
135
+ n = 100
136
+ np.random.seed(42)
137
+ x = np.random.exponential(1, n)
138
+ qq_plot({'x': x}, 'x', \\
139
+ distribution='exp', quantiles=[0, .9], \\
140
+ color='black', line_size=.25)
141
+
142
+ |
143
+
144
+ .. jupyter-execute::
145
+ :linenos:
146
+ :emphasize-lines: 12-13
147
+
148
+ import numpy as np
149
+ from lets_plot.bistro.qq import qq_plot
150
+ from lets_plot import *
151
+ LetsPlot.setup_html()
152
+ n = 100
153
+ np.random.seed(42)
154
+ data = {
155
+ 'x': np.random.normal(0, 1, n),
156
+ 'y': np.random.normal(1, 2, n),
157
+ 'g': np.random.choice(['a', 'b'], n),
158
+ }
159
+ qq_plot(data, x='x', y='y', group='g', \\
160
+ shape=21, alpha=.2, size=5, linetype=5)
161
+
162
+ |
163
+
164
+ .. jupyter-execute::
165
+ :linenos:
166
+ :emphasize-lines: 11-12
167
+
168
+ import numpy as np
169
+ from lets_plot.bistro.qq import qq_plot
170
+ from lets_plot import *
171
+ LetsPlot.setup_html()
172
+ n = 150
173
+ np.random.seed(42)
174
+ data = {
175
+ 'x': np.random.normal(0, 5, n),
176
+ 'g': np.random.choice(['a', 'b', 'c'], n),
177
+ }
178
+ qq_plot(data, 'x', dparams=[0, 5], group='g', \\
179
+ line_color='black', line_size=.5) + \\
180
+ scale_color_brewer(type='qual', palette='Set1') + \\
181
+ facet_grid(x='g') + \\
182
+ coord_fixed() + \\
183
+ xlab("Norm distribution quantiles") + \\
184
+ ggtitle("Interaction of the qq_plot() with other layers") + \\
185
+ theme_classic()
186
+
187
+ """
188
+ return PlotSpec(data=data, mapping=None, scales=[], layers=[], bistro={
189
+ 'name': 'qqplot',
190
+ 'sample': sample,
191
+ 'x': x,
192
+ 'y': y,
193
+ 'distribution': distribution,
194
+ 'dparams': dparams,
195
+ 'quantiles': quantiles,
196
+ 'group': group,
197
+ 'show_legend': show_legend,
198
+ 'marginal': marginal,
199
+ 'color': color,
200
+ 'fill': fill,
201
+ 'alpha': alpha,
202
+ 'size': size,
203
+ 'shape': shape,
204
+ 'line_color': line_color,
205
+ 'line_size': line_size,
206
+ 'linetype': linetype,
207
+ })