lets_plot.ggmarginal¶
- lets_plot.ggmarginal(sides: str, *, size=None, layer: lets_plot.plot.core.LayerSpec) lets_plot.plot.core.FeatureSpec ¶
Convert a given geometry layer to a marginal layer. You can add one or more marginal layers to a plot to create a marginal plot.
- Parameters
- sidesstr
A string specifying which sides of the plot the marginal layer will appear on. It should be set to a string containing any of “trbl”, for top, right, bottom, and left.
- sizenumber or list of numbers, default=0.1
Size of marginal geometry (width or height, depending on the margin side) as a fraction of the entire plotting area of the plot. The value should be in range [0.01..0.95].
- layerLayerSpec
A marginal geometry layer. The result of calling of the geom_xxx() / stat_xxx() function. Marginal plot works best with density,`histogram`,`boxplot`,`violin` and freqpoly geometry layers.
- Returns
- FeatureSpec
An object specifying a marginal geometry layer or a list of marginal geometry layers.
Notes
A marginal plot is a scatterplot (sometimes a 2D density plot or other bivariate plot) that has histograms, boxplots, or other distribution visualization layers in the margins of the x- and y-axes.
Examples
1import numpy as np 2from lets_plot import * 3from lets_plot.mapping import as_discrete 4LetsPlot.setup_html() 5LetsPlot.set_theme(theme_light()) 6 7np.random.seed(0) 8 9cov0=[[1, -.8], 10 [-.8, 1]] 11cov1=[[ 10, .1], 12 [.1, .1]] 13 14x0, y0 = np.random.multivariate_normal(mean=[-2,0], cov=cov0, size=200).T 15x1, y1 = np.random.multivariate_normal(mean=[0,1], cov=cov1, size=200).T 16 17data = dict( 18 x = np.concatenate((x0,x1)), 19 y = np.concatenate((y0,y1)), 20 c = ["A"]*200 + ["B"]*200 21) 22 23p = ggplot(data, aes("x", "y", color="c", fill="c")) + geom_point() 24p + ggmarginal("tr", layer=geom_density(alpha=0.3, show_legend=False))