Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corr plot module #220

Merged
merged 30 commits into from
Nov 23, 2020
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f61a696
fillDiagonal in correlation utils
IKrukov-HORIS Oct 28, 2020
8d5253b
corr.py module
IKrukov-HORIS Oct 28, 2020
879af8a
Removed format parameter
IKrukov-HORIS Oct 28, 2020
fd3d999
Removed _get_format method
IKrukov-HORIS Oct 28, 2020
6927fcd
_tooltip_spec without format parameter
IKrukov-HORIS Oct 28, 2020
4c079ab
flip = True by default
IKrukov-HORIS Oct 28, 2020
d1240b5
flip = True by default
IKrukov-HORIS Oct 28, 2020
53912e8
flip = True by default
IKrukov-HORIS Nov 10, 2020
04bbd2b
_set_diverging_palette renamed to _set_brewer_palette
IKrukov-HORIS Nov 10, 2020
791deef
Using API in build
IKrukov-HORIS Nov 10, 2020
9e6e822
Removed div arg
IKrukov-HORIS Nov 10, 2020
2d0eee9
layers creation deferred till build
IKrukov-HORIS Nov 10, 2020
6dbfcbd
Legend change: Correlation -> Corr
IKrukov-HORIS Nov 11, 2020
4e74f4c
Add fill_scale
IKrukov-HORIS Nov 11, 2020
0f51ad7
tiles implemented via geom_tile
IKrukov-HORIS Nov 11, 2020
f3495e0
Fixed tile implementation.
IKrukov-HORIS Nov 12, 2020
8e4c8e5
Fix height calculation
IKrukov-HORIS Nov 12, 2020
3aabfeb
coord_cartesian when tiles layer is active
IKrukov-HORIS Nov 16, 2020
84d893f
tiles width / height = 0.99
IKrukov-HORIS Nov 17, 2020
663666c
Additive expand 0.5
IKrukov-HORIS Nov 17, 2020
0116ad0
Set fill_diagonal in StatProto
IKrukov-HORIS Nov 17, 2020
7b240e9
Change parameter passing way and some defaults
IKrukov-HORIS Nov 18, 2020
35dda1e
correlation matrix examples
IKrukov-HORIS Nov 18, 2020
709fe1b
Fix typo in methods names
IKrukov-HORIS Nov 18, 2020
ce6aac2
Fix typo in demo
IKrukov-HORIS Nov 18, 2020
25c24b5
Demo layout fix
IKrukov-HORIS Nov 18, 2020
f821be6
brewer palette legend fix
IKrukov-HORIS Nov 19, 2020
80deb81
brewer palette legend fix in demo
IKrukov-HORIS Nov 19, 2020
6eb36e8
brewer palette example update
IKrukov-HORIS Nov 20, 2020
206be8f
add scale_fill_identity for tiles na values
IKrukov-HORIS Nov 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed format parameter
  • Loading branch information
IKrukov-HORIS committed Nov 18, 2020
commit 879af8a13624d315fc88b7fb9f2f0adea8bf1b45
58 changes: 17 additions & 41 deletions python-package/lets_plot/bistro/corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,21 @@ class corr_plot_builder:
This class is intended to build correlation matrix plots.
"""

def __init__(self, data, show_legend=None, format=None, flip=None):
def __init__(self, data, show_legend=None, flip=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets's have: flip=True

"""
Parameters
----------
data : dictionary or pandas DataFrame
Correlation will be calculated for each variable pair.
show_legend : Boolean
If True legend is shown. Default - True.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
flip : Boolean
If True the y axis is flipped.
"""

self._data = data
self._show_legend = show_legend
self._format = format if format else '.2f'
self._format = '.2f'
self._reverse_y = flip if flip else False
self._text_color = None
self._tiles_layer = None
Expand All @@ -60,7 +57,7 @@ def __init__(self, data, show_legend=None, format=None, flip=None):
breaks=[-1.0, -0.5, 0.0, 0.5, 1.0],
limits=[-1.0, 1.0])

def points(self, type=None, fill_diagonal=None, format=None):
def points(self, type=None, fill_diagonal=None):
"""
Method defines correlation matrix layer drawn by points to the plot.

Expand All @@ -70,22 +67,19 @@ def points(self, type=None, fill_diagonal=None, format=None):
Type of matrix. Possible values - "upper", "lower", "full". Default - "full".
fill_diagonal : Boolean
If True the main diagonal is filled with values. Default - True.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.

Returns
-------
self
"""

self._points_layer = geom_point(stat='corr', show_legend=self._show_legend, size_unit='x',
tooltips=self._tooltip_spec(format),
tooltips=self._tooltip_spec(None),
type=self._get_type(type), fill_diagonal=fill_diagonal)

return self

def labels(self, type=None, fill_diagonal=None, format=None, map_size=False, color=None):
def labels(self, type=None, fill_diagonal=None, map_size=False, color=None):
"""
Method defines correlation matrix layer drawn with geom_text to the plot.

Expand All @@ -95,9 +89,6 @@ def labels(self, type=None, fill_diagonal=None, format=None, map_size=False, col
Type of matrix. Possible values - "upper", "lower", "full". Default - "full".
fill_diagonal : Boolean
If True the main diagonal is filled with values. Default - True.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
map_size : Boolean
If True, then absolute value of correlation is mapped to text size. Default - False.
color: string
Expand All @@ -118,14 +109,14 @@ def labels(self, type=None, fill_diagonal=None, format=None, map_size=False, col
other_args['color'] = self._text_color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with text's color if user adds 'tiles' after 'labels'?


self._labels_layer = geom_text(stat='corr', show_legend=self._show_legend,
tooltips=self._tooltip_spec(format),
tooltips=self._tooltip_spec(None),
type=self._get_type(type), fill_diagonal=fill_diagonal,
na_value='', label_format=self._get_format(format),
na_value='', label_format=self._get_format(None),
size_unit = 'x', **other_args)

return self

def tiles(self, type=None, fill_diagonal=None, format=None):
def tiles(self, type=None, fill_diagonal=None):
"""
Method defines correlation matrix layer drawn as square tiles to the plot.

Expand All @@ -135,9 +126,6 @@ def tiles(self, type=None, fill_diagonal=None, format=None):
Type of matrix. Possible values - "upper", "lower", "full". Default - "full".
fill_diagonal : Boolean
If True the main diagonal is filled with values. Default - True.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.

Returns
-------
Expand All @@ -147,7 +135,7 @@ def tiles(self, type=None, fill_diagonal=None, format=None):
self._text_color = 'white'

self._tiles_layer = geom_point(stat='corr', show_legend=self._show_legend, size_unit='x',
tooltips=self._tooltip_spec(format),
tooltips=self._tooltip_spec(None),
type=self._get_type(type), fill_diagonal=fill_diagonal,
size=1.0, shape=15)

Expand Down Expand Up @@ -372,17 +360,14 @@ def _set_diverging_palette(self, palette):
return self


def corr_plot_scatter(data, format=None, palette=None):
def corr_plot_scatter(data, palette=None):
"""
Draws correlation matrix as scatterplot.

Parameters
----------
data : dictionary or pandas DataFrame.
Correlation will be calculated for each variable pair. Required.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
palette : string
Palette name, one of: "BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "Spectral".

Expand All @@ -391,7 +376,7 @@ def corr_plot_scatter(data, format=None, palette=None):
PlotSpec for correlation matrix.
"""

plot_builder = corr_plot_builder(data=data, format=format, flip=True)
plot_builder = corr_plot_builder(data=data, flip=True)
plot_builder.points()

if palette:
Expand All @@ -400,25 +385,22 @@ def corr_plot_scatter(data, format=None, palette=None):
return plot_builder.build()


def corr_plot_tiles(data, format=None, palette=None):
def corr_plot_tiles(data, palette=None):
"""
Draws correlation matrix as tiles.

Parameters
----------
data : dictionary or pandas DataFrame.
Correlation will be calculated for each variable pair. Required.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
palette : string
Palette name, one of: "BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "Spectral".

Returns
-------
PlotSpec for correlation matrix.
"""
plot_builder = corr_plot_builder(data=data, format=format, flip=True)
plot_builder = corr_plot_builder(data=data,flip=True)
plot_builder.tiles()

if palette:
Expand All @@ -427,25 +409,22 @@ def corr_plot_tiles(data, format=None, palette=None):
return plot_builder.build()


def corr_plot_tileslab(data, format=None, palette=None):
def corr_plot_tileslab(data, palette=None):
"""
Draws correlation matrix as tiles with labels.

Parameters
----------
data : dictionary or pandas DataFrame.
Correlation will be calculated for each variable pair. Required.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
palette : string
Palette name, one of: "BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "Spectral".

Returns
-------
PlotSpec for correlation matrix.
"""
plot_builder = corr_plot_builder(data=data, format=format, flip=True)
plot_builder = corr_plot_builder(data=data, flip=True)
plot_builder.tiles()
plot_builder.labels()

Expand All @@ -455,25 +434,22 @@ def corr_plot_tileslab(data, format=None, palette=None):
return plot_builder.build()


def corr_plot_scatterlab(data, format=None, palette=None):
def corr_plot_scatterlab(data, palette=None):
"""
Draws correlation matrix as mix of scattrplot and labels.

Parameters
----------
data : dictionary or pandas DataFrame.
Correlation will be calculated for each variable pair. Required.
format : string
The format to apply to the field. The format contains a number format (1.f) or a string template ({.1f}).
Default - '.2f'.
palette : string
Palette name, one of: "BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "Spectral".

Returns
-------
PlotSpec for correlation matrix.
"""
plot_builder = corr_plot_builder(data=data, format=format, flip=True)
plot_builder = corr_plot_builder(data=data, flip=True)
plot_builder.points(type='lower')
plot_builder.labels(type='upper', fill_diagonal=False, map_size=False)

Expand Down