lets_plot.bistro.corr.corr_plot#
- class lets_plot.bistro.corr.corr_plot(data, show_legend=True, flip=True, threshold=None)#
This class is intended to build correlation matrix plot.
Examples
1import numpy as np 2from lets_plot import * 3from lets_plot.bistro.corr import * 4LetsPlot.setup_html() 5np.random.seed(42) 6data = {var: np.random.poisson(size=10) for var in 'abcdef'} 7corr_plot(data).tiles().build()
1import numpy as np 2from lets_plot import * 3from lets_plot.bistro.corr import * 4LetsPlot.setup_html() 5np.random.seed(42) 6data = {var: np.random.uniform(size=10) for var in 'abcd'} 7corr_plot(data).tiles(type='upper', diag=True)\ 8 .labels(type='upper', diag=True, map_size=True, color='black')\ 9 .palette_RdBu().build()
1import numpy as np 2from lets_plot import * 3from lets_plot.bistro.corr import * 4LetsPlot.setup_html() 5np.random.seed(42) 6data = {var: np.random.normal(size=10) for var in 'abcdef'} 7corr_plot(data, flip=False, threshold=.4).points().labels()\ 8 .palette_gradient(low='#d73027', mid='#ffffbf', high='#1a9850')\ 9 .build()
- __init__(data, show_legend=True, flip=True, threshold=None)#
- Parameters:
- datadict or Pandas or Polars DataFrame
Correlation matrix or data (correlation will be calculated for each variable pair). Data will be recognized as correlation matrix if it has a square shape and all values are in range -1.0..+1.0 or NaN.
- show_legendbool, default=True
If True legend is shown.
- flipbool, default=True
If True the y axis is flipped.
- thresholdfloat, default=0.0
Minimal correlation abs value to be included in result. Accept values between 0 and 1.
- points(type=None, diag=None)#
Method defines correlation matrix layer drawn by points to the plot.
- Parameters:
- type{‘upper’, ‘lower’, ‘full’}
Type of matrix. Default - contextual.
- diagbool
Determines whether to fill the main diagonal with values or not. Default - contextual.
- Returns:
- corr_plot
Correlation plot specification.
- labels(type=None, diag=None, map_size=None, color=None)#
Method defines correlation matrix layer drawn with geom_text to the plot.
- Parameters:
- type{‘upper’, ‘lower’, ‘full’}
Type of matrix. Default - contextual.
- diagbool
Determines whether to fill the main diagonal with values or not. Default - contextual.
- map_sizebool
If True, then absolute value of correlation is mapped to text size. If False - the text size is constant. Default - contextual.
- colorstr
Set text color. For more info see https://lets-plot.org/python/pages/aesthetics.html#color-and-fill. Default - contextual.
- Returns:
- corr_plot
Correlation plot specification.
- tiles(type=None, diag=None)#
Method defines correlation matrix layer drawn as square tiles to the plot.
- Parameters:
- type{‘upper’, ‘lower’, ‘full’}
Type of matrix. Default - contextual.
- diagbool
Determines whether to fill the main diagonal with values or not. Default - contextual.
- Returns:
- corr_plot
Correlation plot specification.
- palette_gradient(low, mid, high)#
Set scale_color_gradient2() and scale_fill_gradient() for corr plot.
- Parameters:
- lowstr
Color for low end of gradient (correlation -1).
- midstr
Color for mid point (correlation 0).
- highstr
Color for high end of gradient (correlation 1).
- Returns:
- corr_plot
Correlation plot specification.
- palette_BrBG()#
Set scale_color_brewer() with BrBG palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_PiYG()#
Set scale_color_brewer() with PiYG palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_PRGn()#
Set scale_color_brewer() with PRGn palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_PuOr()#
Set scale_color_brewer() with PuOr palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_RdBu()#
Set scale_color_brewer() with RdBu palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_RdGy()#
Set scale_color_brewer() with RdGy palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_RdYlBu()#
Set scale_color_brewer() with RdYlBu palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_RdYlGn()#
Set scale_color_brewer() with RdYlGn palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.
- palette_Spectral()#
Set scale_color_brewer() with Spectral palette for corr plot.
- Returns:
- corr_plot
Correlation plot specification.