-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added Animator - added support for pie chart into animator - added bar1 which is just for showing 1d data - changed bars() slightly - removed rotation from corr() labels - added sort to count() - many improvements to line() - some improvements to overlap() - pie() is more or less redone from ground up - scat() is cleaned up - added microseconds to the end of the saved file name string - title is now produced only if there is input for title (no empty space in some plots) - changed the way the tick params for timeseries are handled - added one new exception for the cases where labels are missing - added function for loading data (just placeholder for now) - cleaned up and fixed some issues from transforms.py - added a rational way for sizing of a single seaborn factorplot - added random color option for colors - added new 'colorblind' default that support several kinds of colorblindness - added one more new colorblind palette with 14 colors LOTS OF TESTING! :)
- Loading branch information
1 parent
158d17b
commit cdc1afc
Showing
19 changed files
with
447 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import glob | ||
import os | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from IPython.display import clear_output | ||
|
||
|
||
class Animation(): | ||
|
||
'''ANIMATED CHARTS | ||
Supports dataformat where x and y are compared against each other, and | ||
label_col provides the title (e.g. year) for each frame in the animation. | ||
y and x are used for the legend labels when relevant. | ||
''' | ||
|
||
def __init__(self, data, x, y, label_col, plot_type, filename='animation', | ||
dpi=72, palette='default'): | ||
|
||
self.plot_type = plot_type | ||
self.data = data | ||
self.x = x | ||
self.y = y | ||
self.label_col = label_col | ||
self.palette = palette | ||
self.filename = filename | ||
self.frames = len(data) | ||
self.dpi = dpi | ||
|
||
# RUNTIME | ||
self._ = self._create_plots() | ||
self._ = self._create_gif() | ||
|
||
def _create_plots(self): | ||
|
||
for i in range(self.frames): | ||
data = np.array([self.data[self.x][i], self.data[self.y][i]]).astype(int) | ||
self.plot_type(data, | ||
labels=[self.x, self.y], | ||
palette=self.palette, | ||
sub_title=self.data[self.label_col][i], | ||
save=True, | ||
dpi=self.dpi) | ||
clear_output() | ||
plt.show() | ||
|
||
def _create_gif(self): | ||
|
||
gif_name = self.filename | ||
file_list = glob.glob('astetik_*.png') | ||
list.sort(file_list, key=lambda x: int(x.split('_')[1].split('.png')[0])) | ||
|
||
with open('image_list.txt', 'w') as file: | ||
for item in file_list: | ||
file.write("%s\n" % item) | ||
|
||
os.system('convert @image_list.txt {}.gif'.format(gif_name)) # magick on windows |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# EXCEPTIONAL IMPORT # | ||
import matplotlib | ||
matplotlib.use('Agg') | ||
# ENDS # | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib.pyplot import rcParams | ||
import seaborn as sns | ||
|
||
from ..style.template import _header, _footer | ||
from ..utils.utils import _limiter, _scaler | ||
from ..utils.utils import factorplot_sizing | ||
from ..style.titles import _titles | ||
|
||
|
||
def bar1(data, | ||
x, | ||
y, | ||
multi_color=False, | ||
palette='default', | ||
style='astetik', | ||
dpi=72, | ||
title='', | ||
sub_title='', | ||
x_label='', | ||
y_label='', | ||
legend=True, | ||
x_scale='linear', | ||
y_scale='linear', | ||
x_limit='auto', | ||
y_limit='auto', | ||
save=False): | ||
|
||
'''BAR PLOT | ||
A 1-dimensional bar graph for the case where there is a single | ||
value per label. | ||
Inputs: 2 | ||
1. USE | ||
====== | ||
ast.bar1d(data=patients, | ||
x='icu_days', | ||
y='insurance') | ||
2. PARAMETERS | ||
============= | ||
2.1 INPUT PARAMETERS | ||
-------------------- | ||
data :: pandas dataframe | ||
x :: x-axis data (single value per label) | ||
y :: y-axis data (labels) | ||
-------------------- | ||
2.2. PLOT PARAMETERS | ||
-------------------- | ||
multi_color :: If True, label values will be used for hue. | ||
---------------------- | ||
2.3. COMMON PARAMETERS | ||
---------------------- | ||
palette :: One of the astetik 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' | ||
''' | ||
|
||
size, aspect = factorplot_sizing(data[x]) | ||
|
||
if multi_color == True: | ||
n_colors = len(data[x].unique()) | ||
else: | ||
n_colors = 1 | ||
|
||
# HEADER STARTS >>> | ||
palette = _header(palette, | ||
style, | ||
n_colors=n_colors, | ||
dpi=dpi, | ||
fig_height=None, | ||
fig_width=None) | ||
# <<< HEADER ENDS | ||
p = sns.factorplot(data=data, | ||
x=x, | ||
y=y, | ||
palette=palette, | ||
aspect=aspect, | ||
size=size, | ||
kind='bar') | ||
|
||
# SCALING AND LIMITS STARTS >>> | ||
if x_scale != 'linear' or y_scale != 'linear': | ||
_scaler(p, x_scale, y_scale) | ||
|
||
# FOOTER STARTS >>> | ||
_titles(title, sub_title=sub_title) | ||
_footer(p, x_label, y_label, save=save) | ||
|
||
if data[x].min() < 0: | ||
sns.despine(left=True) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.