lets-plot 4.5.2.dev1__cp310-cp310-win_amd64.whl → 4.6.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/_kbridge.py CHANGED
@@ -6,8 +6,8 @@ from typing import Dict
6
6
 
7
7
  import lets_plot_kotlin_bridge
8
8
 
9
- from ._type_utils import standardize_dict
10
9
  from ._global_settings import get_js_cdn_url
10
+ from ._type_utils import standardize_dict
11
11
 
12
12
 
13
13
  def _generate_dynamic_display_html(plot_spec: Dict) -> str:
@@ -34,3 +34,101 @@ def _standardize_plot_spec(plot_spec: Dict) -> Dict:
34
34
  raise ValueError("dict expected but was {}".format(type(plot_spec)))
35
35
 
36
36
  return standardize_dict(plot_spec)
37
+
38
+
39
+ def _generate_static_configure_html() -> str:
40
+ """
41
+ Generate static HTML configuration.
42
+
43
+ Returns
44
+ -------
45
+ str
46
+ HTML string containing the static configuration with the script URL from global settings.
47
+ """
48
+ scriptUrl = get_js_cdn_url()
49
+ return lets_plot_kotlin_bridge.get_static_configure_html(scriptUrl)
50
+
51
+
52
+ def _generate_display_html_for_raw_spec(
53
+ plot_spec: Dict,
54
+ sizing_options: Dict,
55
+ *,
56
+ dynamic_script_loading: bool = False,
57
+ force_immediate_render: bool = False,
58
+ responsive: bool = False
59
+ ) -> str:
60
+ """
61
+ Generate HTML for displaying a plot from 'raw' specification (not processed by plot backend)
62
+ with customizable options.
63
+
64
+ Parameters
65
+ ----------
66
+ plot_spec : Dict
67
+ Dict containing the plot specification.
68
+ sizing_options : Dict
69
+ Dict containing sizing policy options (width_mode, height_mode, width, height).
70
+ dynamic_script_loading : bool, default=False
71
+ Controls how the generated JS code interacts with the lets-plot JS library.
72
+ If True, assumes the library will be loaded dynamically.
73
+ If False, assumes the library is already present in the page header (static loading).
74
+ force_immediate_render : bool, default=False
75
+ Controls the timing of plot rendering.
76
+ If True, forces immediate plot rendering.
77
+ If False, waits for ResizeObserver(JS) event and renders the plot after the plot
78
+ container is properly layouted in DOM.
79
+ responsive : bool, default=False
80
+ If True, makes the plot responsive to container size changes.
81
+
82
+ Returns
83
+ -------
84
+ str
85
+ HTML string containing the plot with specified options.
86
+
87
+ Notes
88
+ -----
89
+ The sizing_options dict supports the following structure:
90
+ {
91
+ 'width_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
92
+ 'height_mode': str, # 'fixed', 'min', 'fit', 'scaled' (case-insensitive)
93
+ 'width': number, # optional
94
+ 'height': number # optional
95
+ }
96
+
97
+ Sizing modes determine how the plot dimensions are calculated:
98
+
99
+ 1. FIXED mode:
100
+ - Uses the explicitly provided width/height values
101
+ - Falls back to the default figure size if no values provided
102
+ - Not responsive to container size
103
+
104
+ 2. MIN mode:
105
+ Applies the smallest dimension among:
106
+ - The default figure size
107
+ - The specified width/height (if provided)
108
+ - The container size (if available)
109
+
110
+ 3. FIT mode:
111
+ Uses either:
112
+ - The specified width/height if provided
113
+ - Otherwise uses container size if available
114
+ - Falls back to default figure size if neither is available
115
+
116
+ 4. SCALED mode:
117
+ - Always preserves the figure's aspect ratio
118
+ - Typical usage: one dimension (usually width) uses FIXED/MIN/FIT mode
119
+ and SCALED height adjusts to maintain aspect ratio
120
+ - Special case: when both width and height are SCALED:
121
+ * Requires container size to be available
122
+ * Fits figure within container while preserving aspect ratio
123
+ * Neither dimension is predetermined
124
+
125
+ """
126
+ plot_spec = _standardize_plot_spec(plot_spec)
127
+ sizing_options = standardize_dict(sizing_options)
128
+ return lets_plot_kotlin_bridge.get_display_html_for_raw_spec(
129
+ plot_spec,
130
+ sizing_options,
131
+ dynamic_script_loading,
132
+ force_immediate_render,
133
+ responsive
134
+ )
lets_plot/_version.py CHANGED
@@ -3,4 +3,4 @@
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
  # see: https://www.python.org/dev/peps/pep-0440/#developmental-releases
6
- __version__ = '4.5.2.dev1'
6
+ __version__ = '4.6.0'
@@ -36,6 +36,13 @@ def _get_geom2d_layer(geom_kind, binwidth2d, bins2d, color, color_by, size, alph
36
36
  color=color, size=size, alpha=alpha,
37
37
  show_legend=show_legend
38
38
  )
39
+ if geom_kind == 'hex':
40
+ return geom_hex(
41
+ aes(fill=('..count..' if color_by is None else color_by)),
42
+ bins=bins2d, binwidth=binwidth2d,
43
+ color=color, size=size, alpha=alpha,
44
+ show_legend=show_legend
45
+ )
39
46
  if geom_kind == 'density2d':
40
47
  return geom_density2d(
41
48
  aes(color=('..group..' if color_by is None else color_by)),
lets_plot/bistro/im.py CHANGED
@@ -6,14 +6,23 @@ from typing import Any
6
6
 
7
7
  from lets_plot._type_utils import is_ndarray
8
8
  from lets_plot.plot.geom_imshow_ import geom_imshow
9
- from lets_plot.plot.plot import ggplot, GGBunch
9
+ from lets_plot.plot.ggbunch_ import ggbunch
10
+ from lets_plot.plot.plot import ggplot, ggsize, GGBunch
10
11
  from lets_plot.plot.scale_position import scale_x_continuous, scale_y_continuous
12
+ from lets_plot.plot.subplots import SupPlotsSpec
11
13
  from lets_plot.plot.theme_ import theme
12
14
 
13
15
  __all__ = ['image_matrix']
14
16
 
15
17
 
16
- def image_matrix(image_data_array, cmap=None, *, norm=None, vmin=None, vmax=None, scale=1) -> GGBunch:
18
+ def image_matrix(image_data_array,
19
+ cmap=None, *,
20
+ norm=None,
21
+ vmin=None,
22
+ vmax=None,
23
+ scale=1,
24
+ spacer=1,
25
+ ) -> SupPlotsSpec:
17
26
  """
18
27
  Display a set of images in a grid.
19
28
  Dimensions of the grid are determined by the shape of the input Numpy 2D array.
@@ -39,6 +48,8 @@ def image_matrix(image_data_array, cmap=None, *, norm=None, vmin=None, vmax=None
39
48
  This parameter is ignored for RGB(A) images or if parameter `norm=False`.
40
49
  scale : float, default=1.0
41
50
  Specify the image size magnification factor.
51
+ spacer : number, default=1
52
+ Specify the number of pixels between images.
42
53
 
43
54
  Returns
44
55
  -------
@@ -111,13 +122,21 @@ def image_matrix(image_data_array, cmap=None, *, norm=None, vmin=None, vmax=None
111
122
  options = scale_x_continuous(expand=[0, 0])
112
123
  options += scale_y_continuous(expand=[0, 0])
113
124
 
114
- # show no axis
115
- options += theme(axis_line='blank', axis_title='blank', axis_ticks='blank', axis_text='blank')
125
+ # clear all plot decorations, reset plot margins
126
+ options += theme(axis='blank', panel_grid='blank')
127
+ options += theme(plot_inset=0, plot_margin=0, panel_inset=0)
116
128
 
117
- ggbunch = GGBunch()
129
+ figures = []
130
+ regions = []
131
+
132
+ bunch_width = cols * w_max + (cols - 1) * spacer
133
+ bunch_height = rows * h_max + (rows - 1) * spacer
118
134
 
119
135
  for row in range(rows):
120
136
  for col in range(cols):
137
+ figures.append(None)
138
+ regions.append((0, 0, 0, 0))
139
+
121
140
  image_data = image_data_array[row][col]
122
141
  if image_data is None:
123
142
  continue
@@ -133,9 +152,21 @@ def image_matrix(image_data_array, cmap=None, *, norm=None, vmin=None, vmax=None
133
152
  show_legend=False
134
153
  )
135
154
  p += options
136
- ggbunch.add_plot(p, col * w_max, row * h_max, w, h)
155
+ figures[len(figures) - 1] = p
156
+ regions[len(figures) - 1] = (
157
+ col * (w_max + spacer) / bunch_width,
158
+ row * (h_max + spacer) / bunch_height,
159
+ w / bunch_width,
160
+ h / bunch_height
161
+ )
137
162
 
138
- return ggbunch
163
+ return ggbunch(
164
+ plots=figures,
165
+ regions=regions
166
+ ) + ggsize(
167
+ bunch_width,
168
+ bunch_height
169
+ )
139
170
 
140
171
 
141
172
  def _assert_image_data(image_data: Any) -> None:
lets_plot/bistro/joint.py CHANGED
@@ -51,17 +51,17 @@ def joint_plot(data, x, y, *,
51
51
  The data to be displayed.
52
52
  x, y : str
53
53
  Names of a variables.
54
- geom : {'point', 'tile', 'density2d', 'density2df'}, default='point'
54
+ geom : {'point', 'tile', 'hex', 'density2d', 'density2df'}, default='point'
55
55
  The geometric object to use to display the data.
56
56
  bins : int or list of int
57
57
  Number of bins in both directions, vertical and horizontal. Overridden by `binwidth`.
58
58
  If only one value given - interpret it as list of two equal values.
59
- Applicable simultaneously for 'tile' geom and 'histogram' marginal.
59
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
60
60
  binwidth : float or list of float
61
61
  The width of the bins in both directions, vertical and horizontal.
62
62
  Overrides `bins`. The default is to use bin widths that cover the entire range of the data.
63
63
  If only one value given - interpret it as list of two equal values.
64
- Applicable simultaneously for 'tile' geom and 'histogram' marginal.
64
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
65
65
  color : str
66
66
  Color of the geometry.
67
67
  For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
@@ -165,17 +165,17 @@ def residual_plot(data=None, x=None, y=None, *,
165
165
  Random seed for 'loess' sampling.
166
166
  max_n : int
167
167
  Maximum number of data-points for 'loess' method. If this quantity exceeded random sampling is applied to data.
168
- geom : {'point', 'tile', 'density2d', 'density2df', 'none'}, default='point'
168
+ geom : {'point', 'tile', 'hex', 'density2d', 'density2df', 'none'}, default='point'
169
169
  The geometric object to use to display the data. No object will be used if `geom='none'`.
170
170
  bins : int or list of int
171
171
  Number of bins in both directions, vertical and horizontal. Overridden by `binwidth`.
172
172
  If only one value given - interpret it as list of two equal values.
173
- Applicable simultaneously for 'tile' geom and 'histogram' marginal.
173
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
174
174
  binwidth : float or list of float
175
175
  The width of the bins in both directions, vertical and horizontal.
176
176
  Overrides `bins`. The default is to use bin widths that cover the entire range of the data.
177
177
  If only one value given - interpret it as list of two equal values.
178
- Applicable simultaneously for 'tile' geom and 'histogram' marginal.
178
+ Applicable simultaneously for 'tile'/'hex' geom and 'histogram' marginal.
179
179
  color : str
180
180
  Color of the geometry.
181
181
  For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
@@ -1,7 +1,8 @@
1
1
  # Copyright (c) 2024. JetBrains s.r.o.
2
2
  # Use of this source code is governed by the MIT license that can be found in the LICENSE file.
3
3
 
4
- from lets_plot.plot.core import PlotSpec
4
+ from lets_plot.plot.core import PlotSpec, aes
5
+ from lets_plot.plot.util import as_annotated_data
5
6
 
6
7
  __all__ = ['waterfall_plot']
7
8
 
@@ -221,6 +222,7 @@ def waterfall_plot(data, x, y, *,
221
222
  facet_wrap(facets='company', scales='free_x')
222
223
 
223
224
  """
225
+ data, mapping, data_meta = as_annotated_data(data, aes(x=x, y=y))
224
226
  return PlotSpec(data=data, mapping=None, scales=[], layers=[], bistro={
225
227
  'name': 'waterfall',
226
228
  'x': x,
@@ -247,4 +249,4 @@ def waterfall_plot(data, x, y, *,
247
249
  'connector': connector,
248
250
  'label': label,
249
251
  'label_format': label_format,
250
- })
252
+ }, **data_meta)