diff --git a/requirements.txt b/requirements.txt index f473b21..051b877 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,7 @@ flask -flask-cors flask-restplus gunicorn markdown nltk pandas textblob --e git+https://github.com/WaylonWalker/iplotter.git@master#egg=iplotter \ No newline at end of file diff --git a/src/iplotter/__init__.py b/src/iplotter/__init__.py new file mode 100644 index 0000000..4cd17ca --- /dev/null +++ b/src/iplotter/__init__.py @@ -0,0 +1,8 @@ +from .base_plotter import IPlotter +# from .export import VirtualBrowser +from .c3_plotter import C3Plotter +from .plotly_plotter import PlotlyPlotter +from .chartjs_plotter import ChartJSPlotter +from .chartist_plotter import ChartistPlotter +from .google_plotter import GCPlotter +__version__ = '0.4.3' diff --git a/src/iplotter/base_plotter.py b/src/iplotter/base_plotter.py new file mode 100644 index 0000000..70c86ee --- /dev/null +++ b/src/iplotter/base_plotter.py @@ -0,0 +1,55 @@ +from abc import ABCMeta, abstractmethod +import re +import time +# from selenium import webdriver +import os + + +class IPlotter(object): + """Abstract IPlotter""" + + __metaclass__ = ABCMeta + iframe = '' + invalid_name_pattern = re.compile(r'[^a-zA-Z0-9_\-\. ]+') + + def __init__(self): + super(IPlotter, self).__init__() + + @classmethod + def is_valid_name(cls, name): + ''' + check whether plot div id or filenname are valid + ''' + if (cls.invalid_name_pattern.search(name)): + return False + else: + return True + + @abstractmethod + def render(self): + ''' + render the data in HTML template + ''' + pass + + @abstractmethod + def plot(self): + ''' + output an iframe containing the plot in the notebook without saving + ''' + pass + + @abstractmethod + def save(self): + ''' + save the rendered html to a file in the same directory as the notebook + ''' + pass + + @abstractmethod + def plot_and_save(self): + ''' + save the rendered html to a file and return an IFrame to display the + plot in the notebook + ''' + pass diff --git a/src/iplotter/c3_plotter.py b/src/iplotter/c3_plotter.py new file mode 100644 index 0000000..cbfd12f --- /dev/null +++ b/src/iplotter/c3_plotter.py @@ -0,0 +1,386 @@ +from jinja2 import Template +from IPython.display import IFrame, HTML +import os +import json +from .base_plotter import IPlotter +import math + + +class C3Plotter(IPlotter): + """ + Class for creating c3.js charts in ipython notebook + """ + + head = ''' + + + + + + + + ''' + + template = ''' +
import numpy as np # linear algebra
@@ -15,7 +15,7 @@
from subprocess import check_output
@@ -48,7 +48,7 @@
import os
@@ -96,7 +96,7 @@
f = pd.read_csv("C:/Users/alurus/GIT-Repository/VIZ Day/pyDataVizDay2/data/raw/movie_metadata.csv")
@@ -109,11 +109,11 @@
data=DataFrame(f)
-data.head()[:2]
+data.head()[:5]
X_data=data.dtypes[data.dtypes!='object'].index
-X_train=data[X_data]
-X_train.head()[:2]
-# GETTING Correllation matrix
-corr_mat=X_train.corr(method='pearson')
-plt.figure(figsize=(20,10))
-sns.heatmap(corr_mat,vmax=1,square=True,annot=True,cmap='cubehelix')
-!jupyter nbconvert Exploratory_Charts-Movie_Data-Copy2.ipynb --template basic
-df = pd.read_csv('C:/Users/alurus/GIT-Repository/VIZ Day/pyDataVizDay2/data/raw/movie_metadata.csv')
-df.head()
-X_data=data.dtypes[data.dtypes!='object'].index
+X_train=data[X_data]
+X_train.head()[:2]
+# GETTING Correllation matrix
+corr_mat=X_train.corr(method='pearson')
+plt.figure(figsize=(23,10))
+sns.heatmap(corr_mat,vmax=1,square=True,annot=True,cmap='Oranges');
+df = pd.read_csv('C:/Users/alurus/GIT-Repository/VIZ Day/pyDataVizDay/data/raw/movie_metadata.csv')
+df.head()
+df['diff_gross'] = df['gross'] - df['budget']
@@ -3117,10 +3142,10 @@ uhbmo2gAAAAASUVORK5CYII=
aggfunc='sum')
-fig,ax = plt.subplots(figsize=(8,6))
-sns.heatmap(director_budge_pivot['diff_gross'],vmin=0,annot=False,linewidth=.5,ax=ax,cmap='PuBu')
-plt.title('Director vs Year and diff_gross')
-plt.ylabel('Year')
+fig,ax = plt.subplots(figsize=(14,8))
+sns.heatmap(director_budge_pivot['diff_gross'],vmin=0,annot=False,linewidth=.5,ax=ax,cmap='Oranges')
+plt.title('Director vs Year and Share')
+plt.ylabel('Year');
data = pd.read_csv("C:/Users/alurus/GIT-Repository/VIZ Day/pyDataVizDay2/data/raw/movie_metadata.csv")
@@ -3751,15 +3951,23 @@ OJQeAAAAAElFTkSuQmCC
matplotlib.rcParams['figure.figsize'] = (9.0, 5.0)
+matplotlib.rcParams['figure.figsize'] = (18, 9.0)
scores = pd.DataFrame({"imdb score":data["imdb_score"]})
-scores.hist(bins=20)
+scores.hist(bins=20);
plt.figure(figsize = (18, 9))
@@ -4191,13 +4437,21 @@ n0ty44m7n1Br/WKLfgCA5fNRDgAAAKAZH+UAAAAAmhFMAAAAAM0IJgAAAIBmBBMAAABAM/8fUHwp
plt.figure(figsize = (12, 9))
+plt.figure(figsize = (11, 4))
sns.countplot(x = 'content_rating', data = data)
xt = plt.xticks(rotation=56)
@@ -4218,293 +4472,257 @@ n0ty44m7n1Br/WKLfgCA5fNRDgAAAKAZH+UAAAAAmhFMAAAAAM0IJgAAAIBmBBMAAABAM/8fUHwp
@@ -4515,18 +4733,13 @@ luOhAAAAAElFTkSuQmCC
-plt.figure(figsize = (11, 4))
sns.violinplot('content_rating', 'imdb_score', data = data)
+xt = plt.xticks(rotation=45)
!jupyter nbconvert Exploratory_Charts-Movie_Data-Latest_a.ipynb --template basic
+Pf = pd.read_csv('C:/Users/alurus/GIT-Repository/VIZ Day/pyDataVizDay/data/raw/movie_metadata.csv')
+Pf.head([:5];
+