Skip to content

Instantly share code, notes, and snippets.

@zgulde
Created October 19, 2019 01:51
Show Gist options
  • Save zgulde/1a290cfbbc053971ab78af60498a10b4 to your computer and use it in GitHub Desktop.
Save zgulde/1a290cfbbc053971ab78af60498a10b4 to your computer and use it in GitHub Desktop.
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