Skip to content

Commit

Permalink
Merge pull request #26 from mikkokotila/master
Browse files Browse the repository at this point in the history
1.9.5 feature update
  • Loading branch information
mikkokotila committed May 6, 2018
2 parents 94f4ba4 + 2c18786 commit 8bbcf64
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 82 deletions.
24 changes: 21 additions & 3 deletions astetik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@
from .plots.bartwo import bartwo
from .plots.animate import Animation
from .plots.world import world
from .plots.regs import regs
# from .plots.words import words


# TABLES
from .tables.ols import ols
from .tables.table import table
from .tables.text import text
# from .tables.timeseries import timeseries

del plots, style, tables, utils
try:
del plots
except:
pass

__version__ = "1.9.3"
try:
del style
except:
pass

try:
del tables
except:
pass

try:
del utils
except:
pass

__version__ = "1.9.4"
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.3"
__version__ = "1.9.4"
8 changes: 4 additions & 4 deletions astetik/plots/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def bar(data,
1. USE
======
ast.bar1d(data=patients,
x='icu_days',
y='insurance')
ast.bar(data=patients,
x='icu_days',
y='insurance')
2. PARAMETERS
=============
Expand Down Expand Up @@ -122,7 +122,7 @@ def bar(data,
data.columns = [y, x]

if sort != None:
data = data.sort_values(x, ascending=sort)
data = data.sort_values(y, ascending=sort)

if multi_color == True:
n_colors = len(data[x].unique())
Expand Down
6 changes: 4 additions & 2 deletions astetik/plots/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def hist(data,

'''HISTOGRAM
Create a classic histogram.
Create a classic histogram. Note that nans will be
dropped automatically as otherwise seaborn will throw
an error.
Inputs: 1
Features: One continuous
Expand Down Expand Up @@ -123,7 +125,7 @@ def hist(data,
p, ax = plt.subplots(figsize=(params()['fig_width'],
params()['fig_height']))

p = sns.distplot(data[x],
p = sns.distplot(data[x].dropna(),
bins=bins,
norm_hist=False,
kde=False,
Expand Down
147 changes: 147 additions & 0 deletions astetik/plots/regs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
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
from ..utils.utils import _limiter, _scaler


def regs(data,
x,
y,
hue=None,
marker='x',
fit_reg=False,
draw_scatter=True,
logres=False,
palette='default',
style='astetik',
dpi=72,
title='',
sub_title='',
x_label='',
y_label='',
legend=True,
x_scale='linear',
y_scale='linear',
x_limit=None,
y_limit=None,
outliers=False,
save=False):

'''REGRESSION SCATTER PLOT
This can be used as a standard two variable scatter plot
where both variables are continuous. If x is categorical,
use scat() instead or swarm(), depending on your need.
Here you can also choose logres as True in case one of your
variables is a binary categorical.
1. USE
======
p = regs(data=df,
x='Age',
y='Fare',
palette='default',
style='astetik')
2. PARAMETERS
=============
2.1 INPUT PARAMETERS
--------------------
data :: pandas dataframe
x :: x-axis data
y :: y-axis data
--------------------
2.2. PLOT PARAMETERS
--------------------
marker :: By default is 'x' but you can use any matplotlib supported
fit_reg :: If the regression fit should be drawn
draw_scatter :: if the scatter should be drawn
logres :: for logistic regression when one feature is binary categorical.
----------------------
2.3. COMMON PARAMETERS
----------------------
palette :: One of the hand-crafted palettes:
'default'
'colorblind'
'blue_to_red'
'blue_to_green'
'red_to_green'
'green_to_red'
'violet_to_blue'
'brown_to_green'
'green_to_marine'
Or use any cmap, seaborn or matplotlib
color or palette code, or hex value.
style :: Use one of the three core styles:
'astetik' # white
'538' # grey
'solarized' # sepia
Or alternatively use any matplotlib or seaborn
style definition.
dpi :: the resolution of the plot (int value)
title :: the title of the plot (string value)
sub_title :: a secondary title to be shown below the title
x_label :: string value for x-axis label
y_label :: string value for y-axis label
x_scale :: 'linear' or 'log' or 'symlog'
y_scale :: 'linear' or 'log' or 'symlog'
x_limit :: int or list with two ints
y_limit :: int or list with two ints
outliers :: Remove outliers using either 'zscore' or 'iqr'
'''

# HEADER STARTS >>>
palette = _header(palette, style, n_colors=1, dpi=dpi) # NOTE: y exception
# <<< HEADER ENDS

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

sns.regplot(data=data,
x=x, y=y,
fit_reg=fit_reg,
scatter=draw_scatter,
color=palette[0],
marker=marker,
logistic=logres)
# # # # # # PLOT CODE ENDS # # # # # #

# SCALING AND LIMITS STARTS >>>
if x_scale != 'linear' or y_scale != 'linear':
_scaler(p, x_scale, y_scale)

if x_limit != None or y_limit != None:
_limiter(data=data, x=x, y=y, x_limit=x_limit, y_limit=y_limit)

# START OF TITLES >>>
_titles(title, sub_title=sub_title)
_thousand_sep(p, ax)
_footer(p=p, xlabel=x_label, ylabel=y_label, legend=False, n=1, save=save)

ax.xaxis.set_major_locator(plt.MaxNLocator(5))
14 changes: 8 additions & 6 deletions astetik/plots/scat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ def scat(data,

'''SCATTER PLOT
Observations may overlap, and sizing is possible. All except 'hue' should
be continuous variables (or sizing can be stepped). If you want to use
categorical on x-axis, use ast.swarm() or ast.strip() instead.
Well actually, in comparison to a traditional scatter plot, there is
are some limimations here. Observations may overlap, and sizing is
possible. 'x' and 'hue' should not be continuous variables
('size' can be stepped). If you want basic scatter plot, use regs() and
also see swarm() and strip() depending on your data.
1. USE
======
p = scat(data=df,
x='Age',
x='Class',
y='Fare',
hue='Survived',
size='Rand',
Expand Down Expand Up @@ -149,7 +151,7 @@ def scat(data,

# START OF TITLES >>>
_titles(title, sub_title=sub_title)
_thousand_sep(p, ax)
#_thousand_sep(p, ax)
_footer(p, x_label, y_label, legend, n, save)

ax.xaxis.set_major_locator(plt.MaxNLocator(5))
#ax.xaxis.set_major_locator(plt.MaxNLocator(5))
2 changes: 1 addition & 1 deletion astetik/style/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.3"
__version__ = "1.9.4"
2 changes: 1 addition & 1 deletion astetik/tables/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.3"
__version__ = "1.9.4"
49 changes: 0 additions & 49 deletions astetik/tables/ols.py

This file was deleted.

2 changes: 1 addition & 1 deletion astetik/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.3"
__version__ = "1.9.4"
2 changes: 1 addition & 1 deletion astetik/utils/country_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pkg_resources

countries = pkg_resources.resource_filename(__name__, '../extras/countries.csv')
countries = pkg_resources.resource_filename('astetik', 'extras/countries.csv')
countries = pd.read_csv(countries)


Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
matplotlib
seaborn
geonamescache
statsmodels
numpy
pandas
IPython
patsy
statsmodels
19 changes: 9 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
URL = 'http://mikkokotila.com'
LICENSE = 'MIT'
DOWNLOAD_URL = 'https://github.com/mikkokotila/pretty'
VERSION = '1.9.3'
VERSION = '1.9.4'

try:
from setuptools import setup
Expand All @@ -35,6 +35,10 @@
def check_dependencies():
install_requires = []

try:
import matplotlib
except ImportError:
install_requires.append('matplotlib')
try:
import seaborn
except ImportError:
Expand All @@ -43,10 +47,6 @@ def check_dependencies():
import numpy
except ImportError:
install_requires.append('numpy')
#try:
# import matplotlib
#except ImportError:
# install_requires.append('matplotlib')
try:
import pandas
except ImportError:
Expand All @@ -55,10 +55,6 @@ def check_dependencies():
import IPython
except ImportError:
install_requires.append('IPython')
try:
import statsmodels
except ImportError:
install_requires.append('statsmodels')
try:
import patsy
except ImportError:
Expand All @@ -67,7 +63,10 @@ def check_dependencies():
import geonamescache
except ImportError:
install_requires.append('geonamescache')

try:
import statsmodels
except ImportError:
install_requires.append('statsmodels')

return install_requires

Expand Down

0 comments on commit 8bbcf64

Please sign in to comment.