lets-plot 4.5.3a1__cp312-cp312-win_amd64.whl → 4.6.0__cp312-cp312-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/plot/geom.py CHANGED
@@ -12,7 +12,7 @@ from .util import as_annotated_data, is_geo_data_frame, geo_data_frame_to_crs, g
12
12
  #
13
13
  __all__ = ['geom_point', 'geom_path', 'geom_line',
14
14
  'geom_smooth', 'geom_bar',
15
- 'geom_histogram', 'geom_dotplot', 'geom_bin2d',
15
+ 'geom_histogram', 'geom_dotplot', 'geom_bin2d', 'geom_hex',
16
16
  'geom_tile', 'geom_raster',
17
17
  'geom_errorbar', 'geom_crossbar', 'geom_linerange', 'geom_pointrange',
18
18
  'geom_contour',
@@ -128,7 +128,7 @@ def geom_point(mapping=None, *, data=None, stat=None, position=None, show_legend
128
128
 
129
129
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Point` and `MultiPoint`.
130
130
 
131
- The `map` parameter of `Geocoder` type implicitly invokes `centroids()` function.
131
+ The `map` parameter of `Geocoder` type implicitly invokes `get_centroids()` function.
132
132
 
133
133
  ----
134
134
 
@@ -193,7 +193,7 @@ def geom_point(mapping=None, *, data=None, stat=None, position=None, show_legend
193
193
 
194
194
  .. jupyter-execute::
195
195
  :linenos:
196
- :emphasize-lines: 8-11
196
+ :emphasize-lines: 8-12
197
197
 
198
198
  from lets_plot import *
199
199
  from lets_plot.geo_data import *
@@ -205,7 +205,8 @@ def geom_point(mapping=None, *, data=None, stat=None, position=None, show_legend
205
205
  geom_point(aes(size="est_pop_2019"), color="red", show_legend=False, \\
206
206
  data=data, map=centroids, map_join="city", \\
207
207
  tooltips=layer_tooltips().title("@city")
208
- .line("population|@est_pop_2019"))
208
+ .line("population|@est_pop_2019")
209
+ .format("@est_pop_2019", ".2~s"))
209
210
 
210
211
  """
211
212
  return _geom('point',
@@ -938,8 +939,8 @@ def geom_histogram(mapping=None, *, data=None, stat=None, position=None, show_le
938
939
  Result of the call to the `sampling_xxx()` function.
939
940
  To prevent any sampling for this layer pass value "none" (string "none").
940
941
  threshold : float, default=None
941
- If a bin's `..count..` is less than the threshold, the bin will be removed.
942
- Dropping empty bins is particularly useful for faceted plots with free scales.
942
+ If a bin's `..count..` is less than the threshold, it will be removed, but only if it is on the left or right edge of the histogram.
943
+ Dropping empty edge bins is particularly useful for faceted plots with free scales.
943
944
  tooltips : `layer_tooltips`
944
945
  Result of the call to the `layer_tooltips()` function.
945
946
  Specify appearance, style and content.
@@ -1252,10 +1253,6 @@ def geom_bin2d(mapping=None, *, data=None, stat=None, position=None, show_legend
1252
1253
  Apply a rectangular grid to the plane, count observations in each cell (bin) of the grid,
1253
1254
  and map the count to the fill color of the cell (tile).
1254
1255
 
1255
- By default, this geom uses `coord_fixed()`.
1256
- However, this may not be the best choice when the values on the X/Y axis have significantly different magnitudes.
1257
- In such cases, try using `coord_cartesian()`.
1258
-
1259
1256
  Parameters
1260
1257
  ----------
1261
1258
  mapping : `FeatureSpec`
@@ -1420,9 +1417,208 @@ def geom_bin2d(mapping=None, *, data=None, stat=None, position=None, show_legend
1420
1417
  **other_args)
1421
1418
 
1422
1419
 
1420
+ def geom_hex(mapping=None, *, data=None, stat=None, position=None, show_legend=None, inherit_aes=None,
1421
+ manual_key=None, sampling=None,
1422
+ tooltips=None,
1423
+ bins=None,
1424
+ binwidth=None,
1425
+ drop=None,
1426
+ width_unit=None, height_unit=None,
1427
+ color_by=None, fill_by=None,
1428
+ **other_args):
1429
+ """
1430
+ Apply a hexagonal grid to the plane, count observations in each cell (hexagonal bin) of the grid,
1431
+ and map the count to the fill color of the cell (hexagonal tile).
1432
+
1433
+ Parameters
1434
+ ----------
1435
+ mapping : `FeatureSpec`
1436
+ Set of aesthetic mappings created by `aes()` function.
1437
+ Aesthetic mappings describe the way that variables in the data are
1438
+ mapped to plot "aesthetics".
1439
+ data : dict or Pandas or Polars `DataFrame`
1440
+ The data to be displayed in this layer. If None, the default, the data
1441
+ is inherited from the plot data as specified in the call to ggplot.
1442
+ stat : str, default='binhex'
1443
+ The statistical transformation to use on the data for this layer, as a string.
1444
+ position : str or `FeatureSpec`, default='identity'
1445
+ Position adjustment.
1446
+ Either a position adjustment name: 'dodge', 'dodgev', 'jitter', 'nudge', 'jitterdodge', 'fill',
1447
+ 'stack' or 'identity', or the result of calling a position adjustment function (e.g., `position_dodge()` etc.).
1448
+ show_legend : bool, default=True
1449
+ False - do not show legend for this layer.
1450
+ inherit_aes : bool, default=True
1451
+ False - do not combine the layer aesthetic mappings with the plot shared mappings.
1452
+ manual_key : str or `layer_key`
1453
+ The key to show in the manual legend.
1454
+ Specify text for the legend label or advanced settings using the `layer_key()` function.
1455
+ sampling : `FeatureSpec`
1456
+ Result of the call to the `sampling_xxx()` function.
1457
+ To prevent any sampling for this layer pass value "none" (string "none").
1458
+ tooltips : `layer_tooltips`
1459
+ Result of the call to the `layer_tooltips()` function.
1460
+ Specify appearance, style and content.
1461
+ Set tooltips='none' to hide tooltips from the layer.
1462
+ bins : list of int, default=[30, 30]
1463
+ Number of hexagonal bins in both directions, vertical and horizontal. Overridden by `binwidth`.
1464
+ binwidth : list of float
1465
+ The width of the hexagonal bins in both directions, vertical and horizontal.
1466
+ Override `bins`. The default is to use bin widths that cover the entire range of the data.
1467
+ drop : bool, default=True
1468
+ Specify whether to remove all hexagonal bins with 0 counts.
1469
+ width_unit : {'res', 'identity', 'size', 'px'}, default='res'
1470
+ Unit for width of the hexagon.
1471
+ Possible values:
1472
+
1473
+ - 'res': if `stat='binhex'`, the unit equals the hexagonal bin width (`binwidth[0]`); otherwise, it represents the smallest distance between adjacent hexagons along the corresponding axis;
1474
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1475
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1476
+ - 'px': the unit is measured in screen pixels.
1477
+
1478
+ height_unit : {'res', 'identity', 'size', 'px'}, default='res'
1479
+ Unit for height of the hexagon.
1480
+ Possible values:
1481
+
1482
+ - 'res': if `stat='binhex'`, the unit equals the hexagonal bin height (`binwidth[1]`); otherwise, it represents the smallest distance between adjacent hexagons along the corresponding axis;
1483
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1484
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1485
+ - 'px': the unit is measured in screen pixels.
1486
+
1487
+ color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
1488
+ Define the color aesthetic for the geometry.
1489
+ fill_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='fill'
1490
+ Define the fill aesthetic for the geometry.
1491
+ other_args
1492
+ Other arguments passed on to the layer.
1493
+ These are often aesthetics settings used to set an aesthetic to a fixed value,
1494
+ like color='red', fill='blue', size=3 or shape=21.
1495
+ They may also be parameters to the paired geom/stat.
1496
+
1497
+ Returns
1498
+ -------
1499
+ `LayerSpec`
1500
+ Geom object specification.
1501
+
1502
+ Notes
1503
+ -----
1504
+
1505
+ Computed variables:
1506
+
1507
+ - ..count.. : number of points with coordinates in the same hexagonal bin.
1508
+
1509
+ `geom_hex()` understands the following aesthetics mappings:
1510
+
1511
+ - x : x-axis value.
1512
+ - y : y-axis value.
1513
+ - alpha : transparency level of a layer. Accept values between 0 and 1.
1514
+ - color (colour) : color of the geometry lines. For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
1515
+ - fill : fill color. For more info see `Color and Fill <https://lets-plot.org/python/pages/aesthetics.html#color-and-fill>`__.
1516
+ - size : line width, default=0 (i.e. tiles outline initially is not visible).
1517
+ - weight : used by 'binhex' stat to compute weighted sum instead of simple count.
1518
+ - width : width of the hexagon.
1519
+ - height : the real height of the hexagon will be 2/sqrt(3) times this value, so with width=height the hexagon will be the regular.
1520
+
1521
+ ----
1522
+
1523
+ To hide axis tooltips, set 'blank' or the result of `element_blank()`
1524
+ to the `axis_tooltip`, `axis_tooltip_x` or `axis_tooltip_y` parameter of the `theme()`.
1525
+
1526
+ Examples
1527
+ --------
1528
+ .. jupyter-execute::
1529
+ :linenos:
1530
+ :emphasize-lines: 8
1531
+
1532
+ import numpy as np
1533
+ from lets_plot import *
1534
+ LetsPlot.setup_html()
1535
+ np.random.seed(42)
1536
+ mean = np.zeros(2)
1537
+ cov = np.eye(2)
1538
+ x, y = np.random.multivariate_normal(mean, cov, 1000).T
1539
+ ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + geom_hex()
1540
+
1541
+ |
1542
+
1543
+ .. jupyter-execute::
1544
+ :linenos:
1545
+ :emphasize-lines: 9-14
1546
+
1547
+ import numpy as np
1548
+ from lets_plot import *
1549
+ LetsPlot.setup_html()
1550
+ np.random.seed(42)
1551
+ n = 5000
1552
+ x = np.random.uniform(-2, 2, size=n)
1553
+ y = np.random.normal(scale=.5, size=n)
1554
+ ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + \\
1555
+ geom_hex(aes(fill='..density..'), binwidth=[.25, .24], \\
1556
+ tooltips=layer_tooltips().format('@x', '.2f')
1557
+ .format('@y', '.2f').line('(@x, @y)')
1558
+ .line('count|@..count..')
1559
+ .format('@..density..', '.3f')
1560
+ .line('density|@..density..')) + \\
1561
+ scale_fill_gradient(low='black', high='red')
1562
+
1563
+ |
1564
+
1565
+ .. jupyter-execute::
1566
+ :linenos:
1567
+ :emphasize-lines: 10-11
1568
+
1569
+ import numpy as np
1570
+ from lets_plot import *
1571
+ LetsPlot.setup_html()
1572
+ np.random.seed(42)
1573
+ mean = np.zeros(2)
1574
+ cov = [[1, .5],
1575
+ [.5, 1]]
1576
+ x, y = np.random.multivariate_normal(mean, cov, 500).T
1577
+ ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + \\
1578
+ geom_hex(aes(alpha='..count..'), bins=[20, 20], \\
1579
+ fill='darkgreen') + \\
1580
+ geom_point(size=1.5, shape=21, color='white', \\
1581
+ fill='darkgreen') + \\
1582
+ ggsize(600, 450)
1583
+
1584
+ |
1585
+
1586
+ .. jupyter-execute::
1587
+ :linenos:
1588
+ :emphasize-lines: 7-8
1589
+
1590
+ import numpy as np
1591
+ from lets_plot import *
1592
+ LetsPlot.setup_html()
1593
+ np.random.seed(42)
1594
+ x, y = np.random.multivariate_normal(mean=[-98, 39], cov=[[100, 0], [0, 10]], size=100).T
1595
+ ggplot() + geom_livemap() + \\
1596
+ geom_hex(aes(x, y, fill='..density..'), \\
1597
+ bins=[10, 5], alpha=.5, show_legend=False)
1598
+
1599
+ """
1600
+ return _geom('hex',
1601
+ mapping=mapping,
1602
+ data=data,
1603
+ stat=stat,
1604
+ position=position,
1605
+ show_legend=show_legend,
1606
+ inherit_aes=inherit_aes,
1607
+ manual_key=manual_key,
1608
+ sampling=sampling,
1609
+ tooltips=tooltips,
1610
+ bins=bins,
1611
+ binwidth=binwidth,
1612
+ drop=drop,
1613
+ width_unit=width_unit, height_unit=height_unit,
1614
+ color_by=color_by, fill_by=fill_by,
1615
+ **other_args)
1616
+
1617
+
1423
1618
  def geom_tile(mapping=None, *, data=None, stat=None, position=None, show_legend=None, inherit_aes=None,
1424
1619
  manual_key=None, sampling=None,
1425
1620
  tooltips=None,
1621
+ width_unit=None, height_unit=None,
1426
1622
  color_by=None, fill_by=None,
1427
1623
  **other_args):
1428
1624
  """
@@ -1457,6 +1653,24 @@ def geom_tile(mapping=None, *, data=None, stat=None, position=None, show_legend=
1457
1653
  Result of the call to the `layer_tooltips()` function.
1458
1654
  Specify appearance, style and content.
1459
1655
  Set tooltips='none' to hide tooltips from the layer.
1656
+ width_unit : {'res', 'identity', 'size', 'px'}, default='res'
1657
+ Unit for width of the tile.
1658
+ Possible values:
1659
+
1660
+ - 'res': the unit equals the smallest distance between adjacent tiles along the corresponding axis;
1661
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1662
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1663
+ - 'px': the unit is measured in screen pixels.
1664
+
1665
+ height_unit : {'res', 'identity', 'size', 'px'}, default='res'
1666
+ Unit for height of the tile.
1667
+ Possible values:
1668
+
1669
+ - 'res': the unit equals the smallest distance between adjacent tiles along the corresponding axis;
1670
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1671
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1672
+ - 'px': the unit is measured in screen pixels.
1673
+
1460
1674
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
1461
1675
  Define the color aesthetic for the geometry.
1462
1676
  fill_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='fill'
@@ -1568,6 +1782,8 @@ def geom_tile(mapping=None, *, data=None, stat=None, position=None, show_legend=
1568
1782
  manual_key=manual_key,
1569
1783
  sampling=sampling,
1570
1784
  tooltips=tooltips,
1785
+ width_unit=width_unit,
1786
+ height_unit=height_unit,
1571
1787
  color_by=color_by, fill_by=fill_by,
1572
1788
  **other_args)
1573
1789
 
@@ -1670,6 +1886,7 @@ def geom_raster(mapping=None, *, data=None, stat=None, position=None, show_legen
1670
1886
  def geom_errorbar(mapping=None, *, data=None, stat=None, position=None, show_legend=None, inherit_aes=None,
1671
1887
  manual_key=None,
1672
1888
  sampling=None, tooltips=None,
1889
+ width_unit=None, height_unit=None,
1673
1890
  color_by=None,
1674
1891
  **other_args):
1675
1892
  """
@@ -1709,6 +1926,24 @@ def geom_errorbar(mapping=None, *, data=None, stat=None, position=None, show_leg
1709
1926
  Result of the call to the `layer_tooltips()` function.
1710
1927
  Specify appearance, style and content.
1711
1928
  Set tooltips='none' to hide tooltips from the layer.
1929
+ width_unit : {'res', 'identity', 'size', 'px'}, default='res'
1930
+ Unit for the whisker width of the vertical error bar.
1931
+ Possible values:
1932
+
1933
+ - 'res': the unit equals the smallest distance between adjacent error bars along the corresponding axis;
1934
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1935
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1936
+ - 'px': the unit is measured in screen pixels.
1937
+
1938
+ height_unit : {'res', 'identity', 'size', 'px'}, default='res'
1939
+ Unit for the whisker height of the horizontal error bar.
1940
+ Possible values:
1941
+
1942
+ - 'res': the unit equals the smallest distance between adjacent error bars along the corresponding axis;
1943
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
1944
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
1945
+ - 'px': the unit is measured in screen pixels.
1946
+
1712
1947
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
1713
1948
  Define the color aesthetic for the geometry.
1714
1949
  other_args
@@ -1810,6 +2045,8 @@ def geom_errorbar(mapping=None, *, data=None, stat=None, position=None, show_leg
1810
2045
  manual_key=manual_key,
1811
2046
  sampling=sampling,
1812
2047
  tooltips=tooltips,
2048
+ width_unit=width_unit,
2049
+ height_unit=height_unit,
1813
2050
  color_by=color_by,
1814
2051
  **other_args)
1815
2052
 
@@ -1817,6 +2054,7 @@ def geom_errorbar(mapping=None, *, data=None, stat=None, position=None, show_leg
1817
2054
  def geom_crossbar(mapping=None, *, data=None, stat=None, position=None, show_legend=None, inherit_aes=None,
1818
2055
  manual_key=None, sampling=None, tooltips=None,
1819
2056
  fatten=None,
2057
+ width_unit=None,
1820
2058
  color_by=None, fill_by=None,
1821
2059
  **other_args):
1822
2060
  """
@@ -1858,6 +2096,15 @@ def geom_crossbar(mapping=None, *, data=None, stat=None, position=None, show_leg
1858
2096
  Set tooltips='none' to hide tooltips from the layer.
1859
2097
  fatten : float, default=2.5
1860
2098
  A multiplicative factor applied to size of the middle bar.
2099
+ width_unit : {'res', 'identity', 'size', 'px'}, default='res'
2100
+ Unit for the width of the crossbar.
2101
+ Possible values:
2102
+
2103
+ - 'res': the unit equals the smallest distance between adjacent crossbars along the corresponding axis;
2104
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
2105
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
2106
+ - 'px': the unit is measured in screen pixels.
2107
+
1861
2108
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
1862
2109
  Define the color aesthetic for the geometry.
1863
2110
  fill_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='fill'
@@ -1954,6 +2201,7 @@ def geom_crossbar(mapping=None, *, data=None, stat=None, position=None, show_leg
1954
2201
  sampling=sampling,
1955
2202
  tooltips=tooltips,
1956
2203
  fatten=fatten,
2204
+ width_unit=width_unit,
1957
2205
  color_by=color_by, fill_by=fill_by,
1958
2206
  **other_args)
1959
2207
 
@@ -2617,7 +2865,7 @@ def geom_polygon(mapping=None, *, data=None, stat=None, position=None, show_lege
2617
2865
 
2618
2866
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Polygon` and `MultiPolygon`.
2619
2867
 
2620
- The `map` parameter of `Geocoder` type implicitly invokes `boundaries()` function.
2868
+ The `map` parameter of `Geocoder` type implicitly invokes `get_boundaries()` function.
2621
2869
 
2622
2870
  ----
2623
2871
 
@@ -2807,7 +3055,7 @@ def geom_map(mapping=None, *, data=None, stat=None, position=None, show_legend=N
2807
3055
 
2808
3056
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Polygon` and `MultiPolygon`.
2809
3057
 
2810
- The `map` parameter of `Geocoder` type implicitly invokes `boundaries()` function.
3058
+ The `map` parameter of `Geocoder` type implicitly invokes `get_boundaries()` function.
2811
3059
 
2812
3060
  ----
2813
3061
 
@@ -3384,6 +3632,7 @@ def geom_boxplot(mapping=None, *, data=None, stat=None, position=None, show_lege
3384
3632
  outlier_shape=None, outlier_size=None, outlier_stroke=None,
3385
3633
  varwidth=None,
3386
3634
  whisker_width=None,
3635
+ width_unit=None,
3387
3636
  color_by=None, fill_by=None,
3388
3637
  **other_args):
3389
3638
  """
@@ -3441,6 +3690,15 @@ def geom_boxplot(mapping=None, *, data=None, stat=None, position=None, show_lege
3441
3690
  of the number of observations in the groups.
3442
3691
  whisker_width : float, default=0.5
3443
3692
  A multiplicative factor applied to the box width to draw horizontal segments on whiskers.
3693
+ width_unit : {'res', 'identity', 'size', 'px'}, default='res'
3694
+ Unit for the width of the boxplot.
3695
+ Possible values:
3696
+
3697
+ - 'res': the unit equals the smallest distance between adjacent boxes along the corresponding axis;
3698
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
3699
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
3700
+ - 'px': the unit is measured in screen pixels.
3701
+
3444
3702
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
3445
3703
  Define the color aesthetic for the geometry.
3446
3704
  fill_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='fill'
@@ -3578,6 +3836,7 @@ def geom_boxplot(mapping=None, *, data=None, stat=None, position=None, show_lege
3578
3836
  fatten=fatten,
3579
3837
  varwidth=varwidth,
3580
3838
  whisker_width=whisker_width,
3839
+ width_unit=width_unit,
3581
3840
  color_by=color_by, fill_by=fill_by,
3582
3841
  **other_args)
3583
3842
  if stat is None or stat == 'boxplot':
@@ -4652,7 +4911,7 @@ def geom_density(mapping=None, *, data=None, stat=None, position=None, show_lege
4652
4911
 
4653
4912
  .. jupyter-execute::
4654
4913
  :linenos:
4655
- :emphasize-lines: 10
4914
+ :emphasize-lines: 10-11
4656
4915
 
4657
4916
  import numpy as np
4658
4917
  from lets_plot import *
@@ -4660,19 +4919,22 @@ def geom_density(mapping=None, *, data=None, stat=None, position=None, show_lege
4660
4919
  np.random.seed(42)
4661
4920
  x = np.random.normal(size=1000)
4662
4921
  p = ggplot({'x': x}, aes(x='x'))
4663
- bunch = GGBunch()
4664
- for i, bw in enumerate([.1, .2, .4]):
4665
- for j, n in enumerate([16, 64, 256]):
4666
- bunch.add_plot(p + geom_density(kernel='epanechikov', bw=bw, n=n) + \\
4667
- ggtitle('bw={0}, n={1}'.format(bw, n)),
4668
- j * 300, i * 200, 300, 200)
4669
- bunch.show()
4922
+ bandwidths = [0.1, 0.2, 0.4]
4923
+ sample_sizes = [16, 64, 256]
4924
+ plots = [
4925
+ p + geom_density(
4926
+ kernel='epanechikov', bw=bw, n=n
4927
+ ) + ggtitle(f'bw={bw}, n={n}')
4928
+ for bw in bandwidths
4929
+ for n in sample_sizes
4930
+ ]
4931
+ gggrid(plots, ncol=3) + ggsize(900, 600)
4670
4932
 
4671
4933
  |
4672
4934
 
4673
4935
  .. jupyter-execute::
4674
4936
  :linenos:
4675
- :emphasize-lines: 10-11
4937
+ :emphasize-lines: 10-12
4676
4938
 
4677
4939
  import numpy as np
4678
4940
  from lets_plot import *
@@ -4681,13 +4943,15 @@ def geom_density(mapping=None, *, data=None, stat=None, position=None, show_lege
4681
4943
  x = np.random.normal(size=1000)
4682
4944
  y = np.sign(x)
4683
4945
  p = ggplot({'x': x, 'y': y}, aes(x='x'))
4684
- bunch = GGBunch()
4685
- for i, adjust in [(i, .5 * (1 + i)) for i in range(3)]:
4686
- bunch.add_plot(p + geom_density(aes(weight='y'), kernel='cosine', \\
4687
- adjust=adjust) + \\
4688
- ggtitle('adjust={0}'.format(adjust)),
4689
- i * 300, 0, 300, 200)
4690
- bunch.show()
4946
+ adjustments = [0.5 * (1 + i) for i in range(3)]
4947
+ plots = [
4948
+ p + geom_density(
4949
+ aes(weight='y'),
4950
+ kernel='cosine', adjust=adjust
4951
+ ) + ggtitle(f'adjust={adjust}')
4952
+ for adjust in adjustments
4953
+ ]
4954
+ gggrid(plots) + ggsize(800, 200)
4691
4955
 
4692
4956
  """
4693
4957
  return _geom('density',
@@ -4720,10 +4984,6 @@ def geom_density2d(mapping=None, *, data=None, stat=None, position=None, show_le
4720
4984
  """
4721
4985
  Display density function contour.
4722
4986
 
4723
- By default, this geom uses `coord_fixed()`.
4724
- However, this may not be the best choice when the values on the X/Y axis have significantly different magnitudes.
4725
- In such cases, try using `coord_cartesian()`.
4726
-
4727
4987
  Parameters
4728
4988
  ----------
4729
4989
  mapping : `FeatureSpec`
@@ -4847,7 +5107,7 @@ def geom_density2d(mapping=None, *, data=None, stat=None, position=None, show_le
4847
5107
 
4848
5108
  .. jupyter-execute::
4849
5109
  :linenos:
4850
- :emphasize-lines: 12
5110
+ :emphasize-lines: 12-14
4851
5111
 
4852
5112
  import numpy as np
4853
5113
  from lets_plot import *
@@ -4857,19 +5117,23 @@ def geom_density2d(mapping=None, *, data=None, stat=None, position=None, show_le
4857
5117
  x = np.random.normal(size=n)
4858
5118
  y = np.random.normal(size=n)
4859
5119
  p = ggplot({'x': x, 'y': y}, aes('x', 'y'))
4860
- bunch = GGBunch()
4861
- for i, bw in enumerate([.2, .4]):
4862
- for j, n in enumerate([16, 256]):
4863
- bunch.add_plot(p + geom_density2d(kernel='epanechikov', bw=bw, n=n) + \\
4864
- ggtitle('bw={0}, n={1}'.format(bw, n)),
4865
- j * 400, i * 400, 400, 400)
4866
- bunch.show()
5120
+ bandwidths = [0.2, 0.4]
5121
+ sample_sizes = [16, 256]
5122
+ plots = [
5123
+ p + geom_density2d(
5124
+ kernel='epanechikov',
5125
+ bw=bw, n=n
5126
+ ) + ggtitle(f'bw={bw}, n={n}')
5127
+ for bw in bandwidths
5128
+ for n in sample_sizes
5129
+ ]
5130
+ gggrid(plots, ncol=2) + ggsize(600, 650)
4867
5131
 
4868
5132
  |
4869
5133
 
4870
5134
  .. jupyter-execute::
4871
5135
  :linenos:
4872
- :emphasize-lines: 12-13
5136
+ :emphasize-lines: 12-15
4873
5137
 
4874
5138
  import numpy as np
4875
5139
  from lets_plot import *
@@ -4879,14 +5143,18 @@ def geom_density2d(mapping=None, *, data=None, stat=None, position=None, show_le
4879
5143
  x = np.random.normal(size=n)
4880
5144
  y = np.random.normal(size=n)
4881
5145
  p = ggplot({'x': x, 'y': y}, aes('x', 'y'))
4882
- bunch = GGBunch()
4883
- for i, adjust in enumerate([1.5, 2.5]):
4884
- for j, bins in enumerate([5, 15]):
4885
- bunch.add_plot(p + geom_density2d(kernel='cosine', \\
4886
- adjust=adjust, bins=bins) + \\
4887
- ggtitle('adjust={0}, bins={1}'.format(adjust, bins)),
4888
- j * 400, i * 400, 400, 400)
4889
- bunch.show()
5146
+ adjustments = [1.5, 2.5]
5147
+ bin_counts = [5, 15]
5148
+ plots = [
5149
+ p + geom_density2d(
5150
+ kernel='cosine',
5151
+ adjust=adjust,
5152
+ bins=bins
5153
+ ) + ggtitle(f'adjust={adjust}, bins={bins}')
5154
+ for adjust in adjustments
5155
+ for bins in bin_counts
5156
+ ]
5157
+ gggrid(plots, ncol=2) + ggsize(600, 650)
4890
5158
 
4891
5159
  |
4892
5160
 
@@ -4903,7 +5171,7 @@ def geom_density2d(mapping=None, *, data=None, stat=None, position=None, show_le
4903
5171
  y = np.random.normal(size=n)
4904
5172
  ggplot({'x': x, 'y': y}, aes('x', 'y')) + \\
4905
5173
  geom_raster(aes(fill='..density..'), \\
4906
- stat='density2d', contour=False, n=50) + \\
5174
+ stat='density2d', contour=False, n=50) + \\
4907
5175
  scale_fill_gradient(low='#49006a', high='#fff7f3')
4908
5176
 
4909
5177
  |
@@ -4952,10 +5220,6 @@ def geom_density2df(mapping=None, *, data=None, stat=None, position=None, show_l
4952
5220
  """
4953
5221
  Fill density function contour.
4954
5222
 
4955
- By default, this geom uses `coord_fixed()`.
4956
- However, this may not be the best choice when the values on the X/Y axis have significantly different magnitudes.
4957
- In such cases, try using `coord_cartesian()`.
4958
-
4959
5223
  Parameters
4960
5224
  ----------
4961
5225
  mapping : `FeatureSpec`
@@ -5073,7 +5337,7 @@ def geom_density2df(mapping=None, *, data=None, stat=None, position=None, show_l
5073
5337
 
5074
5338
  .. jupyter-execute::
5075
5339
  :linenos:
5076
- :emphasize-lines: 12-13
5340
+ :emphasize-lines: 12-15
5077
5341
 
5078
5342
  import numpy as np
5079
5343
  from lets_plot import *
@@ -5083,20 +5347,24 @@ def geom_density2df(mapping=None, *, data=None, stat=None, position=None, show_l
5083
5347
  x = np.random.normal(size=n)
5084
5348
  y = np.random.normal(size=n)
5085
5349
  p = ggplot({'x': x, 'y': y}, aes(x='x', y='y'))
5086
- bunch = GGBunch()
5087
- for i, bw in enumerate([.2, .4]):
5088
- for j, n in enumerate([16, 256]):
5089
- bunch.add_plot(p + geom_density2df(kernel='epanechikov', bw=bw, n=n, \\
5090
- size=.5, color='white') + \\
5091
- ggtitle('bw={0}, n={1}'.format(bw, n)),
5092
- j * 400, i * 400, 400, 400)
5093
- bunch.show()
5350
+ bandwidths = [0.2, 0.4]
5351
+ sample_sizes = [16, 256]
5352
+ plots = [
5353
+ p + geom_density2df(
5354
+ kernel='epanechikov',
5355
+ size=.5, color='white',
5356
+ bw=bw, n=n
5357
+ ) + ggtitle(f'bw={bw}, n={n}')
5358
+ for bw in bandwidths
5359
+ for n in sample_sizes
5360
+ ]
5361
+ gggrid(plots, ncol=2) + ggsize(600, 650)
5094
5362
 
5095
5363
  |
5096
5364
 
5097
5365
  .. jupyter-execute::
5098
5366
  :linenos:
5099
- :emphasize-lines: 12-14
5367
+ :emphasize-lines: 12-15
5100
5368
 
5101
5369
  import numpy as np
5102
5370
  from lets_plot import *
@@ -5106,15 +5374,18 @@ def geom_density2df(mapping=None, *, data=None, stat=None, position=None, show_l
5106
5374
  x = np.random.normal(size=n)
5107
5375
  y = np.random.normal(size=n)
5108
5376
  p = ggplot({'x': x, 'y': y}, aes(x='x', y='y'))
5109
- bunch = GGBunch()
5110
- for i, adjust in enumerate([1.5, 2.5]):
5111
- for j, bins in enumerate([5, 15]):
5112
- bunch.add_plot(p + geom_density2df(kernel='cosine', \\
5113
- size=.5, color='white', \\
5114
- adjust=adjust, bins=bins) + \\
5115
- ggtitle('adjust={0}, bins={1}'.format(adjust, bins)),
5116
- j * 400, i * 400, 400, 400)
5117
- bunch.show()
5377
+ adjustments = [1.5, 2.5]
5378
+ bin_counts = [5, 15]
5379
+ plots = [
5380
+ p + geom_density2df(
5381
+ kernel='cosine', size=.5, color='white',
5382
+ adjust=adjust,
5383
+ bins=bins
5384
+ ) + ggtitle(f'adjust={adjust}, bins={bins}')
5385
+ for adjust in adjustments
5386
+ for bins in bin_counts
5387
+ ]
5388
+ gggrid(plots, ncol=2) + ggsize(600, 650)
5118
5389
 
5119
5390
  |
5120
5391
 
@@ -6154,7 +6425,7 @@ def geom_rect(mapping=None, *, data=None, stat=None, position=None, show_legend=
6154
6425
 
6155
6426
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `MultiPoint`, `Line`, `MultiLine`, `Polygon` and `MultiPolygon`.
6156
6427
 
6157
- The `map` parameter of `Geocoder` type implicitly invokes `limits()` function.
6428
+ The `map` parameter of `Geocoder` type implicitly invokes `get_limits()` function.
6158
6429
 
6159
6430
  ----
6160
6431
 
@@ -6295,7 +6566,7 @@ def geom_segment(mapping=None, *, data=None, stat=None, position=None, show_lege
6295
6566
  geodesic : bool, default=False
6296
6567
  Draw geodesic. Coordinates expected to be in WGS84. Works only with `geom_livemap()`.
6297
6568
  spacer : float, default=0.0
6298
- Space to shorten a segment by moving the start/end.
6569
+ Pixels to shorten segment, creating gaps at start/end points.
6299
6570
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
6300
6571
  Define the color aesthetic for the geometry.
6301
6572
  other_args
@@ -6462,7 +6733,7 @@ def geom_curve(mapping=None, *, data=None, stat=None, position=None, show_legend
6462
6733
  ncp : int, default=5
6463
6734
  The number of control points used to draw the curve. More control points creates a smoother curve.
6464
6735
  spacer : float, default=0.0
6465
- Space to shorten a curve by moving the start/end.
6736
+ Pixels to shorten segment, creating gaps at start/end points.
6466
6737
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
6467
6738
  Define the color aesthetic for the geometry.
6468
6739
  other_args
@@ -6713,6 +6984,7 @@ def geom_text(mapping=None, *, data=None, stat=None, position=None, show_legend=
6713
6984
  na_text=None,
6714
6985
  nudge_x=None, nudge_y=None,
6715
6986
  size_unit=None,
6987
+ nudge_unit=None,
6716
6988
  check_overlap=None,
6717
6989
  color_by=None,
6718
6990
  **other_args):
@@ -6782,6 +7054,14 @@ def geom_text(mapping=None, *, data=None, stat=None, position=None, show_legend=
6782
7054
  size_unit : {'x', 'y'}
6783
7055
  Relate the size of the text to the length of the unit step along one of the axes.
6784
7056
  If None, no fitting is performed.
7057
+ nudge_unit : {'identity', 'size', 'px'}, default='identity'
7058
+ Units for x and y nudging.
7059
+ Possible values:
7060
+
7061
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
7062
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
7063
+ - 'px': the unit is measured in screen pixels.
7064
+
6785
7065
  check_overlap : bool, default=False
6786
7066
  If True, skip plotting text that overlaps previous text in the same layer.
6787
7067
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
@@ -6820,7 +7100,7 @@ def geom_text(mapping=None, *, data=None, stat=None, position=None, show_legend=
6820
7100
 
6821
7101
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Point` and `MultiPoint`.
6822
7102
 
6823
- The `map` parameter of `Geocoder` type implicitly invokes `centroids()` function.
7103
+ The `map` parameter of `Geocoder` type implicitly invokes `get_centroids()` function.
6824
7104
 
6825
7105
  ----
6826
7106
 
@@ -6934,6 +7214,7 @@ def geom_text(mapping=None, *, data=None, stat=None, position=None, show_legend=
6934
7214
  na_text=na_text,
6935
7215
  nudge_x=nudge_x, nudge_y=nudge_y,
6936
7216
  size_unit=size_unit,
7217
+ nudge_unit=nudge_unit,
6937
7218
  check_overlap=check_overlap,
6938
7219
  color_by=color_by,
6939
7220
  **other_args)
@@ -6949,6 +7230,7 @@ def geom_label(mapping=None, *, data=None, stat=None, position=None, show_legend
6949
7230
  label_padding=None, label_r=None, label_size=None,
6950
7231
  alpha_stroke=None,
6951
7232
  size_unit=None,
7233
+ nudge_unit=None,
6952
7234
  check_overlap=None,
6953
7235
  color_by=None, fill_by=None,
6954
7236
  **other_args):
@@ -7026,6 +7308,14 @@ def geom_label(mapping=None, *, data=None, stat=None, position=None, show_legend
7026
7308
  size_unit : {'x', 'y'}
7027
7309
  Relate the size of the text label to the length of the unit step along one of the axes.
7028
7310
  If None, no fitting is performed.
7311
+ nudge_unit : {'identity', 'size', 'px'}, default='identity'
7312
+ Units for x and y nudging.
7313
+ Possible values:
7314
+
7315
+ - 'identity': a unit of 1 corresponds to a difference of 1 in data space;
7316
+ - 'size': a unit of 1 corresponds to the diameter of a point with `size=1`;
7317
+ - 'px': the unit is measured in screen pixels.
7318
+
7029
7319
  check_overlap : bool, default=False
7030
7320
  If True, skip plotting text that overlaps previous text in the same layer.
7031
7321
  color_by : {'fill', 'color', 'paint_a', 'paint_b', 'paint_c'}, default='color'
@@ -7067,7 +7357,7 @@ def geom_label(mapping=None, *, data=None, stat=None, position=None, show_legend
7067
7357
 
7068
7358
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Point` and `MultiPoint`.
7069
7359
 
7070
- The `map` parameter of `Geocoder` type implicitly invokes `centroids()` function.
7360
+ The `map` parameter of `Geocoder` type implicitly invokes `get_centroids()` function.
7071
7361
 
7072
7362
  ----
7073
7363
 
@@ -7186,6 +7476,7 @@ def geom_label(mapping=None, *, data=None, stat=None, position=None, show_legend
7186
7476
  label_size=label_size,
7187
7477
  alpha_stroke=alpha_stroke,
7188
7478
  size_unit=size_unit,
7479
+ nudge_unit=nudge_unit,
7189
7480
  check_overlap=check_overlap,
7190
7481
  color_by=color_by, fill_by=fill_by,
7191
7482
  **other_args)
@@ -7198,6 +7489,7 @@ def geom_pie(mapping=None, *, data=None, stat=None, position=None, show_legend=N
7198
7489
  hole=None,
7199
7490
  stroke_side=None,
7200
7491
  spacer_width=None, spacer_color=None,
7492
+ start=None, direction=None,
7201
7493
  size_unit=None,
7202
7494
  color_by=None, fill_by=None,
7203
7495
  **other_args):
@@ -7255,10 +7547,15 @@ def geom_pie(mapping=None, *, data=None, stat=None, position=None, show_legend=N
7255
7547
  stroke_side : {'outer', 'inner', 'both'}, default='both'
7256
7548
  Define which arcs of pie sector should have a stroke.
7257
7549
  spacer_width : float, default=0.75
7258
- Line width between sectors.
7550
+ Line width between sectors in pixels.
7259
7551
  Spacers are not applied to exploded sectors and to sides of adjacent sectors.
7260
7552
  spacer_color : str
7261
7553
  Color for spacers between sectors. By default, the "paper" color is used.
7554
+ start : float, default=None
7555
+ Specify the angle at which the first sector starts. Accept values between 0 and 360.
7556
+ Default is a negative angle of the first sector.
7557
+ direction : {1, -1}, default=1
7558
+ Specify angle direction, 1=clockwise, -1=counter-clockwise.
7262
7559
  size_unit : {'x', 'y'}
7263
7560
  Relate the size of the pie chart to the length of the unit step along one of the axes.
7264
7561
  If None, no fitting is performed.
@@ -7305,7 +7602,7 @@ def geom_pie(mapping=None, *, data=None, stat=None, position=None, show_legend=N
7305
7602
 
7306
7603
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Point` and `MultiPoint`.
7307
7604
 
7308
- The `map` parameter of `Geocoder` type implicitly invokes `centroids()` function.
7605
+ The `map` parameter of `Geocoder` type implicitly invokes `get_centroids()` function.
7309
7606
 
7310
7607
  ----
7311
7608
 
@@ -7438,6 +7735,7 @@ def geom_pie(mapping=None, *, data=None, stat=None, position=None, show_legend=N
7438
7735
  stroke_side=stroke_side,
7439
7736
  spacer_width=spacer_width,
7440
7737
  spacer_color=spacer_color,
7738
+ start=start, direction=direction,
7441
7739
  size_unit=size_unit,
7442
7740
  color_by=color_by, fill_by=fill_by,
7443
7741
  **other_args)
@@ -7814,7 +8112,7 @@ def geom_blank(mapping=None, *, data=None, stat=None, position=None, show_legend
7814
8112
 
7815
8113
  The `data` and `map` parameters of `GeoDataFrame` type support shapes `Point` and `MultiPoint`.
7816
8114
 
7817
- The `map` parameter of `Geocoder` type implicitly invokes `centroids()` function.
8115
+ The `map` parameter of `Geocoder` type implicitly invokes `get_centroids()` function.
7818
8116
 
7819
8117
  ----
7820
8118