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

WIP: Refactor layers like ggplot2 [No. 2] #266

Merged
merged 16 commits into from
Apr 30, 2014
1 change: 1 addition & 0 deletions ggplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _set_mpl_backend():
from .ggplot import ggplot
from .components import aes
from .geoms import *
from .stats import *
from .scales import *
from .themes import *
from .utils import *
Expand Down
6 changes: 3 additions & 3 deletions ggplot/components/smoothers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def lm(x, y, alpha=ALPHA):
predict_mean_ci_upp = df['mean_ci_95%_upp']
predict_ci_low = df['predict_ci_95%_low']
predict_ci_upp = df['predict_ci_95%_upp']
return (fittedvalues.tolist(), predict_mean_ci_low.tolist(),
return (x, fittedvalues.tolist(), predict_mean_ci_low.tolist(),
predict_mean_ci_upp.tolist())

def lowess(x, y, span=SPAN):
Expand All @@ -57,7 +57,7 @@ def lowess(x, y, span=SPAN):
std = np.std(y)
y1 = pd.Series(lower * std + y).tolist()
y2 = pd.Series(upper * std + y).tolist()
return (y, y1, y2)
return (x, y, y1, y2)

def mavg(x,y, window):
"compute moving average"
Expand All @@ -68,4 +68,4 @@ def mavg(x,y, window):
y = pd.rolling_mean(y, window)
y1 = y - std_err
y2 = y + std_err
return (y, y1.tolist(), y2.tolist())
return (x, y, y1.tolist(), y2.tolist())
17 changes: 8 additions & 9 deletions ggplot/geoms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@
from .geom_jitter import geom_jitter
from .geom_line import geom_line
from .geom_now_its_art import geom_now_its_art
from .geom_path import geom_path
from .geom_point import geom_point
from .geom_rect import geom_rect
from .geom_smooth import geom_smooth
from .geom_step import geom_step
from .geom_text import geom_text
from .geom_tile import geom_tile
from .geom_vline import geom_vline
# stats
from .stat_bin2d import stat_bin2d
from .stat_function import stat_function
from .stat_smooth import stat_smooth

# misc
from .facet_grid import facet_grid
from .facet_wrap import facet_wrap
from .chart_components import *

__facet__ = ['facet_grid', 'facet_wrap']
__geoms__ = ['geom_abline', 'geom_area', 'geom_bar', 'geom_density',
'geom_histogram', 'geom_hline', 'geom_jitter', 'geom_line',
'geom_now_its_art', 'geom_point', 'geom_rect', 'geom_step',
'geom_text', 'geom_tile', 'geom_vline']
__stats__ = ['stat_bin2d', 'stat_smooth', 'stat_function']
'geom_histogram', 'geom_hline', 'geom_jitter', 'geom_line',
'geom_now_its_art', 'geom_path', 'geom_point', 'geom_rect',
'geom_step', 'geom_smooth', 'geom_text', 'geom_tile',
'geom_vline']
__components__ = ['ylab', 'xlab', 'ylim', 'xlim', 'labs', 'ggtitle']
__all__ = __geoms__ + __facet__ + __stats__ + __components__
__all__ = __geoms__ + __facet__ + __components__
__all__ = [str(u) for u in __all__]
5 changes: 3 additions & 2 deletions ggplot/geoms/facet_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
unicode_literals)
from copy import deepcopy
import math
from ..utils.utils import add_ggplotrc_params
from ..utils.ggutils import add_ggplotrc_params
from ggplot.utils.exceptions import GgplotError


class facet_grid(object):
Expand All @@ -19,7 +20,7 @@ def __radd__(self, gg):
y = gg.data.get(self.y)

if x is None and y is None:
raise Exception("No facets provided!")
raise GgplotError("No facets provided!")

# only do the deepcopy after the check
gg = deepcopy(gg)
Expand Down
5 changes: 3 additions & 2 deletions ggplot/geoms/facet_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
unicode_literals)
from copy import deepcopy
import math
from ..utils.utils import add_ggplotrc_params
from ..utils.ggutils import add_ggplotrc_params
from ggplot.utils.exceptions import GgplotError

class facet_wrap(object):
def __init__(self, x=None, y=None, ncol=None, nrow=None, scales="free"):
if x is None and y is None:
raise Exception("You need to specify a variable name: facet_wrap('var')")
raise GgplotError("You need to specify a variable name: facet_wrap('var')")
add_ggplotrc_params(self)
self.x = x
self.y = y
Expand Down
Loading