lets-plot 4.7.0rc2__cp311-cp311-macosx_11_0_arm64.whl → 4.7.1rc1__cp311-cp311-macosx_11_0_arm64.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.

Files changed (61) hide show
  1. lets_plot/__init__.py +14 -14
  2. lets_plot/_global_settings.py +0 -4
  3. lets_plot/_kbridge.py +11 -3
  4. lets_plot/_version.py +1 -1
  5. lets_plot/bistro/corr.py +28 -27
  6. lets_plot/bistro/im.py +4 -4
  7. lets_plot/bistro/joint.py +7 -7
  8. lets_plot/bistro/qq.py +16 -16
  9. lets_plot/bistro/residual.py +10 -10
  10. lets_plot/bistro/waterfall.py +26 -27
  11. lets_plot/export/ggsave_.py +29 -17
  12. lets_plot/frontend_context/_configuration.py +2 -2
  13. lets_plot/frontend_context/_html_contexts.py +6 -6
  14. lets_plot/geo_data/core.py +26 -22
  15. lets_plot/geo_data/geocoder.py +67 -56
  16. lets_plot/mapping.py +3 -3
  17. lets_plot/package_data/lets-plot.min.js +1 -1
  18. lets_plot/plot/annotation.py +5 -5
  19. lets_plot/plot/coord.py +4 -4
  20. lets_plot/plot/core.py +77 -141
  21. lets_plot/plot/expand_limits_.py +2 -2
  22. lets_plot/plot/facet.py +21 -17
  23. lets_plot/plot/font_features.py +3 -3
  24. lets_plot/plot/geom.py +1129 -1103
  25. lets_plot/plot/geom_extras.py +1 -1
  26. lets_plot/plot/geom_function_.py +16 -13
  27. lets_plot/plot/geom_imshow_.py +8 -7
  28. lets_plot/plot/geom_livemap_.py +38 -13
  29. lets_plot/plot/ggbunch_.py +1 -1
  30. lets_plot/plot/gggrid_.py +3 -3
  31. lets_plot/plot/ggtb_.py +1 -1
  32. lets_plot/plot/guide.py +9 -7
  33. lets_plot/plot/label.py +9 -9
  34. lets_plot/plot/marginal_layer.py +4 -4
  35. lets_plot/plot/plot.py +17 -16
  36. lets_plot/plot/pos.py +15 -15
  37. lets_plot/plot/sampling.py +8 -8
  38. lets_plot/plot/scale.py +153 -150
  39. lets_plot/plot/scale_colormap_mpl.py +9 -6
  40. lets_plot/plot/scale_convenience.py +6 -6
  41. lets_plot/plot/scale_identity_.py +9 -9
  42. lets_plot/plot/scale_position.py +16 -16
  43. lets_plot/plot/series_meta.py +7 -1
  44. lets_plot/plot/stat.py +64 -60
  45. lets_plot/plot/subplots.py +31 -22
  46. lets_plot/plot/theme_.py +93 -92
  47. lets_plot/plot/theme_set.py +15 -14
  48. lets_plot/plot/tooltip.py +14 -14
  49. lets_plot/plot/util.py +33 -3
  50. lets_plot/settings_utils.py +12 -12
  51. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/METADATA +63 -43
  52. lets_plot-4.7.1rc1.dist-info/RECORD +95 -0
  53. lets_plot_kotlin_bridge.cpython-311-darwin.so +0 -0
  54. lets_plot-4.7.0rc2.dist-info/RECORD +0 -95
  55. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/WHEEL +0 -0
  56. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/licenses/LICENSE +0 -0
  57. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/licenses/licenses/LICENSE.FreeType +0 -0
  58. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/licenses/licenses/LICENSE.ImageMagick +0 -0
  59. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/licenses/licenses/LICENSE.expat +0 -0
  60. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/licenses/licenses/LICENSE.fontconfig +0 -0
  61. {lets_plot-4.7.0rc2.dist-info → lets_plot-4.7.1rc1.dist-info}/top_level.txt +0 -0
@@ -113,11 +113,11 @@ class layer_labels(FeatureSpec):
113
113
  a string template ('{.1f}') or a date/time format ('%d.%m.%y').
114
114
  The numeric format for non-numeric value will be ignored.
115
115
  If you need to include a brace character in the literal text,
116
- it can be escaped by doubling: `{{` and `}}`.
116
+ it can be escaped by doubling: ``{{`` and ``}}``.
117
117
 
118
118
  Returns
119
119
  -------
120
- `layer_labels`
120
+ ``layer_labels``
121
121
  Annotations specification.
122
122
 
123
123
  Notes
@@ -179,7 +179,7 @@ class layer_labels(FeatureSpec):
179
179
 
180
180
  Returns
181
181
  -------
182
- `layer_labels`
182
+ ``layer_labels``
183
183
  Annotations specification.
184
184
 
185
185
  Notes
@@ -232,7 +232,7 @@ class layer_labels(FeatureSpec):
232
232
 
233
233
  Returns
234
234
  -------
235
- `layer_labels`
235
+ ``layer_labels``
236
236
  Annotations specification.
237
237
 
238
238
  Examples
@@ -265,7 +265,7 @@ class layer_labels(FeatureSpec):
265
265
 
266
266
  Returns
267
267
  -------
268
- `layer_labels`
268
+ ``layer_labels``
269
269
  Annotations specification.
270
270
 
271
271
  Examples
lets_plot/plot/coord.py CHANGED
@@ -36,7 +36,7 @@ def coord_cartesian(xlim=None, ylim=None, flip=False):
36
36
 
37
37
  Returns
38
38
  -------
39
- `FeatureSpec`
39
+ ``FeatureSpec``
40
40
  Coordinate system specification.
41
41
 
42
42
  Examples
@@ -81,7 +81,7 @@ def coord_fixed(ratio=1., xlim=None, ylim=None, flip=False):
81
81
 
82
82
  Returns
83
83
  -------
84
- `FeatureSpec`
84
+ ``FeatureSpec``
85
85
  Coordinate system specification.
86
86
 
87
87
  Examples
@@ -126,7 +126,7 @@ def coord_map(xlim=None, ylim=None, flip=False):
126
126
 
127
127
  Returns
128
128
  -------
129
- `FeatureSpec`
129
+ ``FeatureSpec``
130
130
  Coordinate system specification.
131
131
 
132
132
  Examples
@@ -164,7 +164,7 @@ def coord_flip(xlim=None, ylim=None):
164
164
 
165
165
  Returns
166
166
  -------
167
- `FeatureSpec`
167
+ ``FeatureSpec``
168
168
  Coordinate system specification.
169
169
 
170
170
  Examples
lets_plot/plot/core.py CHANGED
@@ -9,7 +9,7 @@ from typing import Union
9
9
 
10
10
  __all__ = ['aes', 'layer']
11
11
 
12
- from lets_plot._global_settings import get_global_bool, has_global_value, FRAGMENTS_ENABLED, MAGICK_EXPORT
12
+ from lets_plot._global_settings import get_global_bool, has_global_value, FRAGMENTS_ENABLED
13
13
 
14
14
 
15
15
  def aes(x=None, y=None, **kwargs):
@@ -24,7 +24,7 @@ def aes(x=None, y=None, **kwargs):
24
24
 
25
25
  Returns
26
26
  -------
27
- `FeatureSpec`
27
+ ``FeatureSpec``
28
28
  Aesthetic mapping specification.
29
29
 
30
30
  Notes
@@ -87,17 +87,18 @@ def layer(geom=None, stat=None, data=None, mapping=None, position=None, **kwargs
87
87
  'bin' (count number of points with x-axis coordinate in the same bin),
88
88
  'smooth' (perform smoothing - linear default),
89
89
  'density' (compute and draw kernel density estimate).
90
- data : dict or Pandas or Polars `DataFrame`
90
+ data : dict or Pandas or Polars ``DataFrame``
91
91
  The data to be displayed in this layer. If None, the default, the data
92
92
  is inherited from the plot data as specified in the call to ggplot.
93
- mapping : `FeatureSpec`
94
- Set of aesthetic mappings created by `aes()` function.
93
+ mapping : ``FeatureSpec``
94
+ Set of aesthetic mappings created by `aes() <https://lets-plot.org/python/pages/api/lets_plot.aes.html>`__ function.
95
95
  Aesthetic mappings describe the way that variables in the data are
96
96
  mapped to plot "aesthetics".
97
- position : str or `FeatureSpec`
97
+ position : str or ``FeatureSpec``
98
98
  Position adjustment.
99
99
  Either a position adjustment name: 'dodge', 'jitter', 'nudge', 'jitterdodge', 'fill',
100
- 'stack' or 'identity', or the result of calling a position adjustment function (e.g., `position_dodge()` etc.).
100
+ 'stack' or 'identity', or the result of calling a position adjustment function
101
+ (e.g., `position_dodge() <https://lets-plot.org/python/pages/api/lets_plot.position_dodge.html>`__ etc.).
101
102
  kwargs:
102
103
  Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed
103
104
  value, like color = "red", fill = "blue", size = 3 or shape = 21. They may also be parameters to the
@@ -105,7 +106,7 @@ def layer(geom=None, stat=None, data=None, mapping=None, position=None, **kwargs
105
106
 
106
107
  Returns
107
108
  -------
108
- `LayerSpec`
109
+ ``LayerSpec``
109
110
  Geom object specification.
110
111
 
111
112
  Notes
@@ -162,8 +163,10 @@ class FeatureSpec():
162
163
 
163
164
  Do not use this class explicitly.
164
165
 
165
- Instead, you should construct its objects with functions `ggplot()`, `geom_point()`,
166
- `position_dodge()`, `scale_x_continuous()` etc.
166
+ Instead, you should construct its objects with functions `ggplot() <https://lets-plot.org/python/pages/api/lets_plot.ggplot.html>`__,
167
+ `geom_point() <https://lets-plot.org/python/pages/api/lets_plot.geom_point.html>`__,
168
+ `position_dodge() <https://lets-plot.org/python/pages/api/lets_plot.position_dodge.html>`__,
169
+ `scale_x_continuous() <https://lets-plot.org/python/pages/api/lets_plot.scale_x_continuous.html>`__ etc.
167
170
  """
168
171
 
169
172
  def __init__(self, kind, name, **kwargs):
@@ -179,8 +182,8 @@ class FeatureSpec():
179
182
 
180
183
  def as_dict(self):
181
184
  """
182
- Return the dictionary of all properties of the object with `as_dict()`
183
- applied recursively to all subproperties of `FeatureSpec` type.
185
+ Return the dictionary of all properties of the object with ``as_dict()``
186
+ applied recursively to all subproperties of ``FeatureSpec`` type.
184
187
 
185
188
  Returns
186
189
  -------
@@ -229,8 +232,8 @@ class PlotSpec(FeatureSpec):
229
232
 
230
233
  Do not use this class explicitly.
231
234
 
232
- Instead, you should construct its objects with functions `ggplot()`,
233
- `corr_plot(...).points().build()` etc.
235
+ Instead, you should construct its objects with functions `ggplot() <https://lets-plot.org/python/pages/api/lets_plot.ggplot.html>`__,
236
+ ``corr_plot(...).points().build()`` etc.
234
237
  """
235
238
 
236
239
  @classmethod
@@ -263,7 +266,7 @@ class PlotSpec(FeatureSpec):
263
266
 
264
267
  Returns
265
268
  -------
266
- dict or `DataFrame`
269
+ dict or ``DataFrame``
267
270
  Object data.
268
271
 
269
272
  Examples
@@ -284,7 +287,7 @@ class PlotSpec(FeatureSpec):
284
287
 
285
288
  def has_layers(self) -> bool:
286
289
  """
287
- Check if the `PlotSpec` object has at least one layer.
290
+ Check if the ``PlotSpec`` object has at least one layer.
288
291
 
289
292
  Returns
290
293
  -------
@@ -309,7 +312,7 @@ class PlotSpec(FeatureSpec):
309
312
 
310
313
  def __add__(self, other):
311
314
  """
312
- Allow to add different specs to the `PlotSpec` object.
315
+ Allow to add different specs to the ``PlotSpec`` object.
313
316
 
314
317
  Examples
315
318
  --------
@@ -402,9 +405,11 @@ class PlotSpec(FeatureSpec):
402
405
  return plot
403
406
 
404
407
  if other.kind == 'mapping': # +aes(..)
405
- existing_spec = plot.props().get('mapping', aes())
406
- merged_mapping = {**existing_spec.as_dict(), **other.as_dict()}
407
- plot.props()['mapping'] = aes(**merged_mapping)
408
+ # existing_spec = plot.props().get('mapping', aes())
409
+ # merged_mapping = {**existing_spec.as_dict(), **other.as_dict()}
410
+ # plot.props()['mapping'] = aes(**merged_mapping)
411
+ from lets_plot.plot.util import update_plot_aes_mapping # local import to break circular reference
412
+ update_plot_aes_mapping(plot, other)
408
413
  return plot
409
414
 
410
415
  # add feature to properties
@@ -468,19 +473,25 @@ class PlotSpec(FeatureSpec):
468
473
  from ..frontend_context._configuration import _display_plot
469
474
  _display_plot(self)
470
475
 
471
- def to_svg(self, path=None) -> str:
476
+ def to_svg(self, path=None, w=None, h=None, unit=None) -> str:
472
477
  """
473
478
  Export the plot in SVG format.
474
479
 
475
480
  Parameters
476
481
  ----------
477
- self : `PlotSpec`
482
+ self : ``PlotSpec``
478
483
  Plot specification to export.
479
484
  path : str, file-like object, default=None
480
485
  Сan be either a string specifying a file path or a file-like object.
481
486
  If a string is provided, the result will be exported to the file at that path.
482
487
  If a file-like object is provided, the result will be exported to that object.
483
488
  If None is provided, the result will be returned as a string.
489
+ w : float, default=None
490
+ Width of the output image in units.
491
+ h : float, default=None
492
+ Height of the output image in units.
493
+ unit : {'in', 'cm', 'mm', 'px'}, default='in'
494
+ Unit of the output image. One of: 'in', 'cm', 'mm' or 'px'.
484
495
 
485
496
  Returns
486
497
  -------
@@ -505,7 +516,7 @@ class PlotSpec(FeatureSpec):
505
516
  p.to_svg(file_like)
506
517
  display.SVG(file_like.getvalue())
507
518
  """
508
- return _to_svg(self, path)
519
+ return _to_svg(self, path, w=w, h=h, unit=unit)
509
520
 
510
521
  def to_html(self, path=None, iframe: bool = None) -> str:
511
522
  """
@@ -513,7 +524,7 @@ class PlotSpec(FeatureSpec):
513
524
 
514
525
  Parameters
515
526
  ----------
516
- self : `PlotSpec`
527
+ self : ``PlotSpec``
517
528
  Plot specification to export.
518
529
  path : str, file-like object, default=None
519
530
  Сan be either a string specifying a file path or a file-like object.
@@ -552,7 +563,7 @@ class PlotSpec(FeatureSpec):
552
563
 
553
564
  Parameters
554
565
  ----------
555
- self : `PlotSpec`
566
+ self : ``PlotSpec``
556
567
  Plot specification to export.
557
568
  path : str, file-like object
558
569
  Сan be either a string specifying a file path or a file-like object.
@@ -566,12 +577,17 @@ class PlotSpec(FeatureSpec):
566
577
  h : float, default=None
567
578
  Height of the output image in units.
568
579
  Only applicable when exporting to PNG or PDF.
569
- unit : {'in', 'cm', 'mm'}, default='in'
570
- Unit of the output image. One of: 'in', 'cm', 'mm'.
580
+ unit : {'in', 'cm', 'mm', 'px'}, default='in'
581
+ Unit of the output image. One of: 'in', 'cm', 'mm' or 'px'.
571
582
  Only applicable when exporting to PNG or PDF.
572
583
  dpi : int, default=300
573
584
  Resolution in dots per inch.
574
585
  Only applicable when exporting to PNG or PDF.
586
+ The default value depends on the unit:
587
+
588
+ - for 'px' it is 96 (output image will have the same pixel size as ``w`` and ``h`` values)
589
+ - for physical units ('in', 'cm', 'mm') it is 300
590
+
575
591
 
576
592
  Returns
577
593
  -------
@@ -580,24 +596,24 @@ class PlotSpec(FeatureSpec):
580
596
 
581
597
  Notes
582
598
  -----
583
- - If `w`, `h`, `unit`, and `dpi` are all specified:
599
+ - If ``w``, ``h``, ``unit``, and ``dpi`` are all specified:
584
600
 
585
- - The plot's pixel size (default or set by `ggsize()`) is ignored.
586
- - The output size is calculated using the specified `w`, `h`, `unit`, and `dpi`.
601
+ - The plot's pixel size (default or set by `ggsize() <https://lets-plot.org/python/pages/api/lets_plot.ggsize.html>`__) is ignored.
602
+ - The output size is calculated using the specified ``w``, ``h``, ``unit``, and ``dpi``.
587
603
 
588
- - The plot is resized to fit the specified `w` x `h` area, which may affect the layout, tick labels, and other elements.
604
+ - The plot is resized to fit the specified ``w`` x ``h`` area, which may affect the layout, tick labels, and other elements.
589
605
 
590
- - If only `dpi` is specified:
606
+ - If only ``dpi`` is specified:
591
607
 
592
- - The plot's pixel size (default or set by `ggsize()`) is converted to inches using the standard display PPI of 96.
608
+ - The plot's pixel size (default or set by `ggsize() <https://lets-plot.org/python/pages/api/lets_plot.ggsize.html>`__) is converted to inches using the standard display PPI of 96.
593
609
  - The output size is then calculated based on the specified DPI.
594
610
 
595
611
  - The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
596
612
  - Useful for printing - the plot will appear nearly the same size as on screen.
597
613
 
598
- - If `w`, `h` are not specified:
614
+ - If ``w``, ``h`` are not specified:
599
615
 
600
- - The `scale` parameter is used to determine the output size.
616
+ - The ``scale`` parameter is used to determine the output size.
601
617
 
602
618
  - The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
603
619
  - Useful for generating high-resolution images suitable for publication.
@@ -628,7 +644,7 @@ class PlotSpec(FeatureSpec):
628
644
 
629
645
  Parameters
630
646
  ----------
631
- self : `PlotSpec`
647
+ self : ``PlotSpec``
632
648
  Plot specification to export.
633
649
  path : str, file-like object
634
650
  Сan be either a string specifying a file path or a file-like object.
@@ -642,12 +658,17 @@ class PlotSpec(FeatureSpec):
642
658
  h : float, default=None
643
659
  Height of the output image in units.
644
660
  Only applicable when exporting to PNG or PDF.
645
- unit : {'in', 'cm', 'mm'}, default='in'
646
- Unit of the output image. One of: 'in', 'cm', 'mm'.
661
+ unit : {'in', 'cm', 'mm', 'px'}, default='in'
662
+ Unit of the output image. One of: 'in', 'cm', 'mm' or 'px'.
647
663
  Only applicable when exporting to PNG or PDF.
648
664
  dpi : int, default=300
649
665
  Resolution in dots per inch.
650
666
  Only applicable when exporting to PNG or PDF.
667
+ The default value depends on the unit:
668
+
669
+ - for 'px' it is 96 (output image will have the same pixel size as ``w`` and ``h`` values)
670
+ - for physical units ('in', 'cm', 'mm') it is 300
671
+
651
672
 
652
673
  Returns
653
674
  -------
@@ -656,24 +677,24 @@ class PlotSpec(FeatureSpec):
656
677
 
657
678
  Notes
658
679
  -----
659
- - If `w`, `h`, `unit`, and `dpi` are all specified:
680
+ - If ``w``, ``h``, ``unit``, and ``dpi`` are all specified:
660
681
 
661
- - The plot's pixel size (default or set by `ggsize()`) is ignored.
662
- - The output size is calculated using the specified `w`, `h`, `unit`, and `dpi`.
682
+ - The plot's pixel size (default or set by `ggsize() <https://lets-plot.org/python/pages/api/lets_plot.ggsize.html>`__) is ignored.
683
+ - The output size is calculated using the specified ``w``, ``h``, ``unit``, and ``dpi``.
663
684
 
664
- - The plot is resized to fit the specified `w` x `h` area, which may affect the layout, tick labels, and other elements.
685
+ - The plot is resized to fit the specified ``w`` x ``h`` area, which may affect the layout, tick labels, and other elements.
665
686
 
666
- - If only `dpi` is specified:
687
+ - If only ``dpi`` is specified:
667
688
 
668
- - The plot's pixel size (default or set by `ggsize()`) is converted to inches using the standard display PPI of 96.
689
+ - The plot's pixel size (default or set by `ggsize() <https://lets-plot.org/python/pages/api/lets_plot.ggsize.html>`__) is converted to inches using the standard display PPI of 96.
669
690
  - The output size is then calculated based on the specified DPI.
670
691
 
671
692
  - The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
672
693
  - Useful for printing - the plot will appear nearly the same size as on screen.
673
694
 
674
- - If `w`, `h` are not specified:
695
+ - If ``w``, ``h`` are not specified:
675
696
 
676
- - The `scale` parameter is used to determine the output size.
697
+ - The ``scale`` parameter is used to determine the output size.
677
698
 
678
699
  - The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
679
700
  - Useful for generating high-resolution images suitable for publication.
@@ -708,8 +729,10 @@ class LayerSpec(FeatureSpec):
708
729
 
709
730
  Do not use this class explicitly.
710
731
 
711
- Instead, you should construct its objects with functions `geom_point()`,
712
- `geom_contour()`, `geom_boxplot()`, `geom_text()` etc.
732
+ Instead, you should construct its objects with functions `geom_point() <https://lets-plot.org/python/pages/api/lets_plot.geom_point.html>`__,
733
+ `geom_contour() <https://lets-plot.org/python/pages/api/lets_plot.geom_contour.html>`__,
734
+ `geom_boxplot() <https://lets-plot.org/python/pages/api/lets_plot.geom_boxplot.html>`__,
735
+ `geom_text() <https://lets-plot.org/python/pages/api/lets_plot.geom_text.html>`__ etc.
713
736
  """
714
737
 
715
738
  __own_features = ['geom', 'stat', 'mapping', 'position']
@@ -870,18 +893,19 @@ def _merge_dicts_recursively(d1, d2):
870
893
 
871
894
  def _theme_dicts_merge(x, y):
872
895
  """
873
- Simple values in `y` override values in `x`.
874
- If values in `y` and `x` both are dictionaries, then they are merged.
896
+ Simple values in ``y`` override values in ``x``.
897
+ If values in ``y`` and ``x`` both are dictionaries, then they are merged.
875
898
  """
876
899
  overlapping_keys = x.keys() & y.keys()
877
900
  z = {k: {**x[k], **y[k]} for k in overlapping_keys if type(x[k]) is dict and type(y[k]) is dict}
878
901
  return {**x, **y, **z}
879
902
 
880
903
 
881
- def _to_svg(spec, path) -> Union[str, None]:
904
+ def _to_svg(spec, path, w=None, h=None, unit=None) -> Union[str, None]:
882
905
  from .. import _kbridge as kbr
883
906
 
884
- svg = kbr._generate_svg(spec.as_dict())
907
+ svg = kbr._generate_svg(spec.as_dict(), w, h, unit, use_css_pixelated_image_rendering=True)
908
+
885
909
  if path is None:
886
910
  return svg
887
911
  elif isinstance(path, str):
@@ -914,31 +938,6 @@ def _to_html(spec, path, iframe: bool) -> Union[str, None]:
914
938
 
915
939
 
916
940
  def _export_as_raster(spec, path, scale: float, export_format: str, w=None, h=None, unit=None, dpi=None) -> Union[str, None]:
917
- if get_global_bool(MAGICK_EXPORT):
918
- if w is None and h is None and unit is None and dpi is None:
919
- def_scale = 2.0
920
- def_dpi = -1
921
- def_unit = ""
922
- else:
923
- def_scale = 1.0
924
- def_dpi = 300
925
- def_unit = 'in'
926
-
927
- return _export_with_magick(
928
- spec,
929
- path,
930
- scale if scale is not None else def_scale,
931
- export_format,
932
- w if w is not None else -1,
933
- h if h is not None else -1,
934
- unit if unit is not None else def_unit,
935
- dpi if dpi is not None else def_dpi
936
- )
937
- else:
938
- return _export_with_cairo(spec, path, scale, export_format, w, h, unit, dpi)
939
-
940
-
941
- def _export_with_magick(spec, path, scale: float, export_format: str, w, h, unit, dpi) -> Union[str, None]:
942
941
  import base64
943
942
  from .. import _kbridge
944
943
 
@@ -949,7 +948,7 @@ def _export_with_magick(spec, path, scale: float, export_format: str, w, h, unit
949
948
  file_like_object = path
950
949
  file_path = None
951
950
 
952
- png_base64 = _kbridge._export_png(spec.as_dict(), float(w), float(h), unit, int(dpi), float(scale))
951
+ png_base64 = _kbridge._generate_png(spec.as_dict(), w, h, unit, dpi, scale)
953
952
  png = base64.b64decode(png_base64)
954
953
 
955
954
  if export_format.lower() == 'png':
@@ -988,53 +987,6 @@ def _export_with_magick(spec, path, scale: float, export_format: str, w, h, unit
988
987
  raise ValueError("Unknown export format: {}".format(export_format))
989
988
 
990
989
 
991
- def _export_with_cairo(spec, path, scale: float, export_format: str, w=None, h=None, unit=None, dpi=None) -> Union[str, None]:
992
- from .. import _kbridge
993
-
994
- input = None
995
- export_function = None
996
-
997
- if export_format.lower() == 'png' or export_format.lower() == 'pdf':
998
- try:
999
- import cairosvg
1000
- except ImportError:
1001
- import sys
1002
- print("\n"
1003
- "To export Lets-Plot figure to a PNG or PDF file please install CairoSVG library"
1004
- "to your Python environment.\n"
1005
- "CairoSVG is free and distributed under the LGPL-3.0 license.\n"
1006
- "For more details visit: https://cairosvg.org/documentation/\n", file=sys.stderr)
1007
- return None
1008
-
1009
- if export_format.lower() == 'png':
1010
- export_function = cairosvg.svg2png
1011
- elif export_format.lower() == 'pdf':
1012
- export_function = cairosvg.svg2pdf
1013
-
1014
- # Use SVG image-rendering style as Cairo doesn't support CSS image-rendering style,
1015
- input = _kbridge._generate_svg(spec.as_dict(), use_css_pixelated_image_rendering=False)
1016
- else:
1017
- raise ValueError("Unknown export format: {}".format(export_format))
1018
-
1019
- if isinstance(path, str):
1020
- abspath = _makedirs(path)
1021
- result = abspath
1022
- else:
1023
- result = None # file-like object is provided. No path to return.
1024
-
1025
- if any(it is not None for it in [w, h, unit, dpi]):
1026
- if w is None or h is None or unit is None or dpi is None:
1027
- raise ValueError("w, h, unit, and dpi must all be specified")
1028
-
1029
- w, h = _to_inches(w, unit) * dpi, _to_inches(h, unit) * dpi
1030
- export_function(bytestring=input, write_to=path, dpi=dpi, output_width=w, output_height=h)
1031
- else:
1032
- scale = scale if scale is not None else 2.0
1033
- export_function(bytestring=input, write_to=path, scale=scale)
1034
-
1035
- return result
1036
-
1037
-
1038
990
  def _makedirs(path: str) -> str:
1039
991
  """Return absolute path to a file after creating all directories in the path."""
1040
992
  abspath = os.path.abspath(path)
@@ -1042,19 +994,3 @@ def _makedirs(path: str) -> str:
1042
994
  if dirname and not os.path.exists(dirname):
1043
995
  os.makedirs(dirname)
1044
996
  return abspath
1045
-
1046
-
1047
- def _to_inches(size, size_unit):
1048
- if size_unit is None:
1049
- raise ValueError("Unit must be specified")
1050
-
1051
- if size_unit == 'in':
1052
- inches = size
1053
- elif size_unit == 'cm':
1054
- inches = size / 2.54
1055
- elif size_unit == 'mm':
1056
- inches = size / 25.4
1057
- else:
1058
- raise ValueError("Unknown unit: {}. Expected one of: 'in', 'cm', 'mm'".format(size_unit))
1059
-
1060
- return inches
@@ -11,7 +11,7 @@ def expand_limits(*, x=None, y=None, size=None, color=None, fill=None, alpha=Non
11
11
 
12
12
  This function extends the plot boundaries to encompass new data points,
13
13
  whether a single value or multiple values are provided. It acts as a
14
- thin wrapper around `geom_blank()`.
14
+ thin wrapper around `geom_blank() <https://lets-plot.org/python/pages/api/lets_plot.geom_blank.html>`__.
15
15
 
16
16
  Parameters
17
17
  ----------
@@ -22,7 +22,7 @@ def expand_limits(*, x=None, y=None, size=None, color=None, fill=None, alpha=Non
22
22
  Returns
23
23
  -------
24
24
  FeatureSpec
25
- A result of the `geom_blank()` call.
25
+ A result of the `geom_blank() <https://lets-plot.org/python/pages/api/lets_plot.geom_blank.html>`__ call.
26
26
 
27
27
  Examples
28
28
  --------
lets_plot/plot/facet.py CHANGED
@@ -38,21 +38,21 @@ def facet_grid(x=None, y=None, *, scales=None, x_order=1, y_order=1,
38
38
  Specify the format pattern for displaying faceting values in rows.
39
39
  x_labwidth : int, default=None
40
40
  The maximum label length (in characters) before a line breaking is applied.
41
- If the original facet label already contains `\\\\n` as a text separator, it splits at those points first,
42
- then wraps each part according to `x_labwidth`.
41
+ If the original facet label already contains ``\\\\n`` as a text separator, it splits at those points first,
42
+ then wraps each part according to ``x_labwidth``.
43
43
  y_labwidth : int, default=None
44
44
  The maximum label length (in characters) before a line breaking is applied.
45
- If the original facet label already contains `\\\\n` as a text separator, it splits at those points first,
46
- then wraps each part according to `y_labwidth`.
45
+ If the original facet label already contains ``\\\\n`` as a text separator, it splits at those points first,
46
+ then wraps each part according to ``y_labwidth``.
47
47
 
48
48
  Returns
49
49
  -------
50
- `FeatureSpec`
50
+ ``FeatureSpec``
51
51
  Facet grid specification.
52
52
 
53
53
  Notes
54
54
  -----
55
- Format pattern in the `x_format` / `y_format` parameters can be
55
+ Format pattern in the ``x_format`` / ``y_format`` parameters can be
56
56
  just a number format (like 'd') or a string template where number format
57
57
  is surrounded by curly braces: "{d} cylinders".
58
58
 
@@ -107,11 +107,11 @@ def facet_grid(x=None, y=None, *, scales=None, x_order=1, y_order=1,
107
107
  x_labwidth=x_labwidth, y_labwidth=y_labwidth)
108
108
 
109
109
 
110
- def facet_wrap(facets, ncol=None, nrow=None, *, scales=None, order=1, format=None, dir="h", labwidth=None):
110
+ def facet_wrap(facets, ncol=None, nrow=None, *, scales=None, order=1, format=None, drop=None, dir="h", labwidth=None):
111
111
  """
112
112
  Split data by one or more faceting variables.
113
113
  For each data subset creates a plot panel and lays out panels
114
- according to the `ncol`, `nrow` and `dir` settings.
114
+ according to the ``ncol``, ``nrow`` and ``dir`` settings.
115
115
 
116
116
  Parameters
117
117
  ----------
@@ -122,31 +122,34 @@ def facet_wrap(facets, ncol=None, nrow=None, *, scales=None, order=1, format=Non
122
122
  nrow : int
123
123
  Number of rows.
124
124
  scales : str
125
- Specify whether scales are shared across all facets.
125
+ Specifies whether scales are shared across all facets.
126
126
  'fixed' - shared (the default), 'free' - vary across both rows and columns,
127
127
  'free_x' or 'free_y' - vary across rows or columns respectively.
128
128
  order : int or list, default=1
129
- Specify ordering direction panels. 1 - ascending, -1 - descending, 0 - no ordering.
130
- When a list is given, then values in the list are positionally matched to variables in `facets`.
129
+ Specify the ordering direction of panels. 1 - ascending, -1 - descending, 0 - no ordering.
130
+ When a list is given, then values in the list are positionally matched to variables in ``facets``.
131
131
  format : str or list
132
132
  Specify the format pattern for displaying faceting values.
133
- The `format` values are positionally matched to variables in `facets`.
133
+ The ``format`` values are positionally matched to variables in ``facets``.
134
+ drop : bool, default=True
135
+ Specifies whether to drop unused factor levels (the default behavior)
136
+ or to show all factor levels regardless of whether they occur in the data.
134
137
  dir : {'h', 'v'}, default='h'
135
- Direction: either 'h' for horizontal, or 'v' for vertical.
138
+ Direction: either 'h' for horizontal or 'v' for vertical.
136
139
  labwidth : int or list
137
140
  The maximum label length (in characters) before a line breaking is applied.
138
- If the original facet label already contains `\\\\n` as a text separator, it splits at those points first,
139
- then wraps each part according to `labwidth`.
141
+ If the original facet label already contains ``\\\\n`` as a text separator, it splits at those points first,
142
+ then wraps each part according to ``labwidth``.
140
143
 
141
144
 
142
145
  Returns
143
146
  -------
144
- `FeatureSpec`
147
+ ``FeatureSpec``
145
148
  Facet wrap specification.
146
149
 
147
150
  Notes
148
151
  -----
149
- Format patterns in the `format` parameter can be just a number format (like 'd') or
152
+ Format patterns in the ``format`` parameter can be just a number format (like 'd') or
150
153
  a string template where number format is surrounded by curly braces: "{d} cylinders".
151
154
 
152
155
  For example:
@@ -198,6 +201,7 @@ def facet_wrap(facets, ncol=None, nrow=None, *, scales=None, order=1, format=Non
198
201
  scales=scales,
199
202
  order=order,
200
203
  format=format,
204
+ drop=drop,
201
205
  dir=dir,
202
206
  labwidth=labwidth)
203
207
 
@@ -21,7 +21,7 @@ def font_metrics_adjustment(width_correction: numbers.Real) -> FeatureSpec:
21
21
 
22
22
  Returns
23
23
  -------
24
- `FeatureSpec`
24
+ ``FeatureSpec``
25
25
  Metainfo specification.
26
26
 
27
27
  Notes
@@ -51,11 +51,11 @@ def font_family_info(family: str, width_correction: numbers.Real = None, mono: b
51
51
  width_correction : number, optional
52
52
  Correcting coefficient applied to default width estimate of a text label.
53
53
  mono : bool, optional
54
- When True - the font is marked as `monospaced`.
54
+ When True - the font is marked as 'monospaced'.
55
55
 
56
56
  Returns
57
57
  -------
58
- `FeatureSpec`
58
+ ``FeatureSpec``
59
59
  Metainfo specification.
60
60
 
61
61
  Notes