Skip to content

Commit

Permalink
Merge pull request #20 from mikkokotila/master
Browse files Browse the repository at this point in the history
1.9.3 Feature Update
  • Loading branch information
mikkokotila committed Apr 28, 2018
2 parents 2bf572b + 3608622 commit 94f4ba4
Show file tree
Hide file tree
Showing 48 changed files with 572 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.pyc
__pycache__
5 changes: 3 additions & 2 deletions astetik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .plots.bar import bar
from .plots.bartwo import bartwo
from .plots.animate import Animation
from .plots.world import world
# from .plots.words import words


Expand All @@ -28,6 +29,6 @@
from .tables.text import text
# from .tables.timeseries import timeseries

from .utils.transform import boolcols_to_cat
del plots, style, tables, utils

__version__ = "1.9.2"
__version__ = "1.9.3"
250 changes: 250 additions & 0 deletions astetik/extras/countries.csv

Large diffs are not rendered by default.

Binary file added astetik/extras/countries.dbf
Binary file not shown.
Binary file added astetik/extras/countries.shp
Binary file not shown.
Binary file added astetik/extras/countries.shx
Binary file not shown.
2 changes: 1 addition & 1 deletion astetik/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.2"
__version__ = "1.9.3"
2 changes: 2 additions & 0 deletions astetik/plots/animate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import glob
import os
import numpy as np
# EXCEPTIONAL IMPORT #

import matplotlib.pyplot as plt

from IPython.display import clear_output
Expand Down
11 changes: 3 additions & 8 deletions astetik/plots/bar.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# EXCEPTIONAL IMPORT #
import matplotlib
matplotlib.use('Agg')
# ENDS #

import seaborn as sns
import pandas as pd

from ..style.template import _header, _footer
from ..utils.utils import _limiter, _scaler
from ..utils.utils import _scaler
from ..utils.utils import factorplot_sizing
from ..style.titles import _titles

Expand All @@ -28,8 +23,8 @@ def bar(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''BAR PLOT
Expand Down
13 changes: 3 additions & 10 deletions astetik/plots/bargrid.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# EXCEPTIONAL IMPORT #
import matplotlib
matplotlib.use('Agg')
# ENDS #

import matplotlib.pyplot as plt
from matplotlib.pyplot import rcParams
import seaborn as sns

from ..style.template import _header, _footer
from ..utils.utils import _limiter, _scaler
from ..utils.utils import _scaler


def bargrid(data,
Expand All @@ -28,8 +21,8 @@ def bargrid(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''BAR PLOT
Expand Down
28 changes: 10 additions & 18 deletions astetik/plots/bartwo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# EXCEPTIONAL IMPORT #
import matplotlib
matplotlib.use('Agg')
# ENDS #

import seaborn as sns
import pandas as pd

from ..style.template import _header, _footer
from ..utils.utils import _limiter, _scaler
from ..utils.utils import _scaler
from ..utils.utils import factorplot_sizing
from ..style.titles import _titles

Expand All @@ -29,20 +23,16 @@ def bartwo(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''2-D BAR PLOT
A 2-dimensional bar graph for the case where there is a continuous
variable that is compared against labels and a single categorial.
is a single
value per label. Accepts either dataframe or series. If series,
then labels will come from index.
Inputs: 1 (Series), 2(DataFrame)
variable that is compared against labels and a single categorial. The
'x' is the continuous variable, 'y' is the labels (categorical) and
'hue' is the comparison color.
1. USE
======
Expand All @@ -56,9 +46,11 @@ def bartwo(data,
--------------------
data :: pandas dataframe
x :: x-axis data (single value per label)
x :: x-axis data (continuous)
y :: y-axis data (category labels)
y :: y-axis data (labels)
hue :: color comparison data (preferably binary categorical)
--------------------
2.2. PLOT PARAMETERS
Expand Down
6 changes: 2 additions & 4 deletions astetik/plots/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def box(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''BOX PLOT
Expand Down Expand Up @@ -131,8 +131,6 @@ def box(data,
if x_scale != 'linear' or y_scale != 'linear':
_scaler(p, x_scale, y_scale)

_thousand_sep(p, ax)

if x_limit != None or y_limit != None:
_limiter(data=data, x=x, y=y, x_limit=None, y_limit=y_limit)
# <<< SCALING AND LIMITS ENDS
Expand Down
4 changes: 2 additions & 2 deletions astetik/plots/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def compare(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''COMPARE PLOT
Expand Down
48 changes: 34 additions & 14 deletions astetik/plots/corr.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import warnings
warnings.filterwarnings("ignore")

import numpy as np
import seaborn as sns
import matplotlib
matplotlib.use('Agg')
# ENDS #
import matplotlib.pyplot as plt
import seaborn as sns



from ..style.formats import _thousand_sep
from ..style.style import params
from ..style.titles import _titles
from ..style.template import _header, _footer

Expand All @@ -12,8 +19,10 @@ def corr(data,
corr_method='spearman',
annot=False,
mask=True,
line_width=2,
line_color='white',
line_width=1,
line_color='black',
color_grades=5,
auto_sizing=True,
palette='default',
style='astetik',
dpi=72,
Expand All @@ -24,14 +33,14 @@ def corr(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''CORRELATION HEATMAP
This is best used with less than 10 variables in the datasetself.
For best results, split the analysis to several parts.
This is best used with less than 50 variables in the dataset.
For best results, column labels should be clear and not too long.
Inputs: a dataframe with several columns
Features: Both categorical and continuous features will be used
Expand Down Expand Up @@ -74,6 +83,14 @@ def corr(data,
to set small when there are really many items.
line_color :: the color of the lines between the elements e.g. 'black'
auto_sizing :: If not True, then should be int value in inches which is used
for both width and height.
color_grades :: The number of colors/shades to use in total. 5 is default.
Generally the best results come with 3 or 5 or 7, but looks
better with more colors.
----------------------
2.3. COMMON PARAMETERS
----------------------
Expand Down Expand Up @@ -126,31 +143,34 @@ def corr(data,
if mask == True:
mask = np.zeros_like(data)
mask[np.triu_indices_from(mask)] = True
line_color = 'white'
else:
mask = None
# # # # # PREP ENDS # # # # #

# HEADER STARTS >>>
palette = _header(palette,
style,
n_colors=10,
n_colors=color_grades,
dpi=dpi)

if auto_sizing == True:
size = data.shape[0] / 2 + 5

# PLOT
p, ax = plt.subplots(figsize=(params()['fig_width'],
params()['fig_height']))
p, ax = plt.subplots(figsize=(size, size))

p = sns.heatmap(data,
mask=mask,
linewidths=line_width,
linecolor=line_color,
cmap=palette,
annot=annot,
square=True)
annot=annot)

# HEADER
_thousand_sep(p, ax)
_titles(title, sub_title=sub_title)
_footer(p, x_label, y_label, save=save, tight=False, despine=False)

p.set_xticklabels(data)
p.set_xticklabels(data, rotation=90)
p.set_yticklabels(data, rotation=0)
4 changes: 2 additions & 2 deletions astetik/plots/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def count(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''COUNT PLOT
Expand Down
16 changes: 9 additions & 7 deletions astetik/plots/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def grid(data,
legend=True,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''THE GRID
Expand All @@ -47,9 +47,9 @@ def grid(data,
--------------------
data :: pandas dataframe
x :: x-axis data (categorical)
x :: x-axis data (continuous or categorical)
y :: y-axis data (continuous or categorical)
y :: y-axis data (continuous)
hue :: color highlight (categorical)
Expand Down Expand Up @@ -108,9 +108,11 @@ def grid(data,
'''

data = data.copy(deep=True)
n_colors = 1
if hue is True:
hue = len(data[hue].unique())

if hue != None:
n_colors = len(data[hue].unique())
else:
n_colors = 1

# HEADER STARTS >>>
palette = _header(palette,
Expand Down
6 changes: 3 additions & 3 deletions astetik/plots/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def hist(data,
legend=False,
x_scale='linear',
y_scale='linear',
x_limit='auto',
y_limit='auto',
x_limit=None,
y_limit=None,
save=False):

'''HISTOGRAM
Expand Down Expand Up @@ -111,7 +111,7 @@ def hist(data,
warnings.simplefilter("ignore")

if bins == True:
bins = int(len(data[x].unique()) / 10)
bins = int(len(data[x].unique()) / 10) + 5

if dropna is True:
data = data[data[x].isna() == False]
Expand Down
1 change: 0 additions & 1 deletion astetik/plots/kde.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import seaborn as sns
import matplotlib.pyplot as plt

Expand Down
Loading

0 comments on commit 94f4ba4

Please sign in to comment.