Created
October 19, 2019 01:51
-
-
Save zgulde/1a290cfbbc053971ab78af60498a10b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from pydataset import data | |
class Plot: | |
def __init__(self, data=None): | |
if data is not None: | |
self.data = data | |
def __getattr__(self, attr): | |
def wrapper(*args, **kwargs): | |
if attr in ['scatter', 'hist', 'bar', 'plot'] and 'data' not in kwargs: | |
kwargs['data'] = self.data | |
getattr(plt, attr)(*args, **kwargs) | |
return self | |
return wrapper | |
tips = data('tips') | |
Plot(tips).scatter('total_bill', 'tip') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment