Skip to content

Commit

Permalink
release: grplot-0.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiffaryr committed Dec 25, 2022
1 parent 27c54f4 commit acf2eda
Show file tree
Hide file tree
Showing 13 changed files with 355 additions and 58 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ The latest stable release (and required dependencies) can be installed from PyPI

pip install grplot

The latest stable release (and required dependencies) can be installed from Conda:

conda install -c conda-forge grplot


Development
-----------
Expand Down
249 changes: 233 additions & 16 deletions doc/Documentation Notebook.ipynb

Large diffs are not rendered by default.

55 changes: 42 additions & 13 deletions grplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from matplotlib import pyplot as plt
import numpy
from grplot.features.filter.check_filter import check_filter
from grplot.features.optimizer.optimizer_data import optimizer_data
from grplot.features.pad.check_pad import check_pad
from grplot.features.plot.plot_type import plot_type
Expand All @@ -10,7 +11,7 @@
from grplot.utils.strtoarray import strtoarray


__version__ = '0.12.1'
__version__ = '0.13.1'


def plot2d(plot, # default general value
Expand All @@ -23,6 +24,7 @@ def plot2d(plot, # default general value
pad=6,
hpad=None,
wpad=None,
filter=None,
hue=None,
size=None, # {5:'stripplot+swarmplot'}
fontsize=10,
Expand Down Expand Up @@ -198,10 +200,10 @@ def plot2d(plot, # default general value
by ghiffary rifqialdi
based on numpy, scipy, matplotlib, seaborn, squarify, pandas, and ipython
version = '0.12.1'
version = '0.13.1'
release date
27/09/2022
26/12/2022
-----------------------------------------------
documentation is available at https://github.com/ghiffaryr/grplot
Expand All @@ -227,8 +229,11 @@ def plot2d(plot, # default general value
# single plot, x axis
if (type(x) == str) and (y is None):
i = 0
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x,
y=None,
hue=hue,
Expand Down Expand Up @@ -287,16 +292,19 @@ def plot2d(plot, # default general value
# single plot, y axis
elif (x is None) and (type(y) == str):
i = 0
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=None,
y=y,
hue=hue,
size=size,
style=style,
units=units,
axes='[{}]'.format(i+1),
mode=optimizer)
mode=optimizer)
plot_type(plot=plot, data=df_optimized, x=None, y=y, ax=ax, axes='[{}]'.format(i+1), hue=hue, size=size, style=style, palette=palette, hue_order=hue_order, hue_norm=hue_norm, sizes=sizes, size_order=size_order, size_norm=size_norm, markers=markers, dashes=dashes, style_order=style_order, legend=legend, height=height, units=units, x_bins=x_bins, y_bins=y_bins, estimator=estimator, x_estimator=x_estimator, ci=ci, n_boot=n_boot, alpha=alpha, expand_margins=expand_margins, jitter=jitter, x_jitter=x_jitter, y_jitter=y_jitter, weights=weights, color=color, seed=seed, sort=sort, err_style=err_style, err_kws=err_kws, stat=stat, bins=bins, binwidth=binwidth, binrange=binrange, discrete=discrete, cumulative=cumulative, common_bins=common_bins, common_norm=common_norm, common_grid=common_grid, multiple=multiple, element=element, fill=fill, shrink=shrink, kde=kde, kde_kws=kde_kws, line_kws=line_kws, thresh=thresh, pthresh=pthresh, pmax=pmax, cbar=cbar, cbar_ax=cbar_ax, cbar_kws=cbar_kws, shade=shade, vertical=vertical, kernel=kernel, bw=bw, gridsize=gridsize, cut=cut, clip=clip, shade_lowest=shade_lowest, levels=levels, bw_method=bw_method, bw_adjust=bw_adjust, data2=df2, warn_singular=warn_singular, complementary=complementary, a=a, order=order, orient=orient, edgecolor=edgecolor, linewidth=linewidth, saturation=saturation, width=width, dodge=dodge, fliersize=fliersize, whis=whis, scale=scale, scale_hue=scale_hue, inner=inner, split=split, k_depth=k_depth, outlier_prop=outlier_prop, trust_alpha=trust_alpha, showfliers=showfliers, linestyles=linestyles, join=join, errwidth=errwidth, capsize=capsize, errcolor=errcolor, x_ci=x_ci, scatter=scatter, fit_reg=fit_reg, logistic=logistic, lowess=lowess, robust=robust, regplot_logx=regplot_logx, x_partial=x_partial, y_partial=y_partial, truncate=truncate, scatter_kws=scatter_kws, marker=marker, dropna=dropna, label=label, zorder=zorder, color2=color2, markersize=markersize, explode=explode, colors=colors, autopct=autopct, pctdistance=pctdistance, shadow=shadow, labeldistance=labeldistance, startangle=startangle, radius=radius, counterclock=counterclock, wedgeprops=wedgeprops, textprops=textprops, center=center, frame=frame, rotatelabels=rotatelabels, normalize=normalize, norm_x=norm_x, norm_y=norm_y, treemaps_pad=treemaps_pad, bar_kwargs=bar_kwargs, text_kwargs=text_kwargs, bubble_spacing=bubble_spacing, showmeans=showmeans, meanprops=meanprops, text=text)
setting(plot=plot,
df=df_optimized,
Expand Down Expand Up @@ -347,8 +355,11 @@ def plot2d(plot, # default general value
# single plot, x and y axis
elif (type(x) == str) and (type(y) == str):
i = 0
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x,
y=y,
hue=hue,
Expand Down Expand Up @@ -414,8 +425,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x[flag],
y=None,
hue=hue,
Expand Down Expand Up @@ -481,8 +495,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{},{}]'.format(i+1,j+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x[flag],
y=None,
hue=hue,
Expand Down Expand Up @@ -549,8 +566,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=None,
y=y[flag],
hue=hue,
Expand Down Expand Up @@ -616,8 +636,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{},{}]'.format(i+1,j+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=None,
y=y[flag],
hue=hue,
Expand Down Expand Up @@ -685,8 +708,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{}]'.format(i+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x[flag],
y=y[flag],
hue=hue,
Expand Down Expand Up @@ -751,8 +777,11 @@ def plot2d(plot, # default general value
break
else:
pass
df_filter = check_filter(df=df,
logic=filter,
axes='[{},{}]'.format(i+1,j+1))
df_optimized = optimizer_data(plot=plot,
df=df,
df=df_filter,
x=x[flag],
y=y[flag],
hue=hue,
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions grplot/features/filter/check_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from grplot.features.filter.filter_def import filter_def
from grplot.utils.arg_ax_type import arg_ax_type

def check_filter(df, logic, axes):
logic = arg_ax_type(arg=logic, axes=axes)
# check logic
if logic is None:
return df
else:
df_filter = filter_def(df=df, logic=logic)
return df_filter
24 changes: 24 additions & 0 deletions grplot/features/filter/filter_def.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy
import pandas
from grplot.utils.check_data_structure import check_data_structure


def filter_def(df, logic):
# data structure
data_structure = check_data_structure(df)
if data_structure == 'pandas dataframe':
if type(logic) == str:
try:
df_filter = df.query(logic)
except:
raise Exception('Wrong pandas query argument!')
elif (type(logic) == pandas.core.series.Series) and (logic.dtype == bool):
try:
df_filter = df[logic]
except:
raise Exception('Wrong pandas filter argument!')
else:
raise Exception('Unsupported filter argument for pandas data type!')
else:
raise Exception('Unsupported data structure for filter argument!')
return df_filter
12 changes: 6 additions & 6 deletions grplot/features/optimizer/optimizer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def optimizer_data(plot, df, x, y, hue, size, style, units, axes, mode):
for k in numpy.unique(key):
if k in df.keys():
if type(df[k]) == list:
if mode in ['numpy','saver']:
if mode in ['numpy', 'saver']:
df_[k] = numpy.array(df[k])
elif mode in ['pandas','perf']:
elif mode in ['pandas', 'perf']:
df_ = pandas.DataFrame.from_dict({k: df[k] for k in numpy.unique(key) if k in df.keys()})
break
else:
raise Exception('Unknown optimizer argument!')
elif type(df[k]) == numpy.ndarray:
if mode in ['numpy','saver']:
if mode in ['numpy', 'saver']:
df_[k] = df[k]
elif mode in ['pandas','perf']:
elif mode in ['pandas', 'perf']:
df_ = pandas.DataFrame.from_dict({k: df[k] for k in numpy.unique(key) if k in df.keys()})
break
else:
Expand All @@ -44,9 +44,9 @@ def optimizer_data(plot, df, x, y, hue, size, style, units, axes, mode):
else:
pass
elif type(df) == pandas.core.frame.DataFrame:
if mode in ['numpy','saver']:
if mode in ['numpy', 'saver']:
df_ = {k: df[[k]].to_records()[k] for k in numpy.unique(key) if k in df}
elif mode in ['pandas','perf']:
elif mode in ['pandas', 'perf']:
df_ = df[[k for k in numpy.unique(key) if k in df]]
# if there is only one column
if type(df_) == pandas.core.series.Series:
Expand Down
2 changes: 1 addition & 1 deletion grplot/features/optimizer/optimizer_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def optimizer_key(var_list):
key = numpy.array([])
if type(var_list) in [list, numpy.ndarray]:
for var in var_list:
if type(var) == str:
if type(var) in [str, numpy.str_]:
key = numpy.concatenate([key, numpy.array([var])])
elif type(var) == list:
key = numpy.concatenate([key, numpy.array(var)])
Expand Down
26 changes: 7 additions & 19 deletions grplot/features/text/text_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,12 @@ def text_def(plot, df, ax, ci, hue, multiple, axis, text, sep, add, text_fontsiz
for data in ax.get_shared_y_axes().get_siblings(ax)[0].get_lines():
x_arr, y_arr = data.get_data()
# check x_arr data type
if type(x_arr) == list:
x_arr = numpy.array(x_arr)
elif numpy.issubdtype(type(x_arr), numpy.ndarray) == False:
if (type(x_arr) == list) or (numpy.issubdtype(type(x_arr), numpy.ndarray) == False):
x_arr = numpy.array(x_arr)
else:
pass
# check y_arr data type
if type(y_arr) == list:
y_arr = numpy.array(y_arr)
elif numpy.issubdtype(type(y_arr), numpy.ndarray) == False:
if (type(y_arr) == list) or (numpy.issubdtype(type(y_arr), numpy.ndarray) == False):
y_arr = numpy.array(y_arr)
else:
pass
Expand All @@ -275,16 +271,12 @@ def text_def(plot, df, ax, ci, hue, multiple, axis, text, sep, add, text_fontsiz
for data in ax.get_shared_x_axes().get_siblings(ax)[0].get_lines():
x_arr, y_arr = data.get_data()
# check x_arr data type
if type(x_arr) == list:
x_arr = numpy.array(x_arr)
elif numpy.issubdtype(type(x_arr), numpy.ndarray) == False:
if (type(x_arr) == list) or (numpy.issubdtype(type(x_arr), numpy.ndarray) == False):
x_arr = numpy.array(x_arr)
else:
pass
# check y_arr data type
if type(y_arr) == list:
y_arr = numpy.array(y_arr)
elif numpy.issubdtype(type(y_arr), numpy.ndarray) == False:
if (type(y_arr) == list) or (numpy.issubdtype(type(y_arr), numpy.ndarray) == False):
y_arr = numpy.array(y_arr)
else:
pass
Expand Down Expand Up @@ -381,16 +373,12 @@ def text_def(plot, df, ax, ci, hue, multiple, axis, text, sep, add, text_fontsiz
for data in ax.get_lines():
x_arr, y_arr = data.get_data()
# check x_arr data type
if type(x_arr) == list:
x_arr = numpy.array(x_arr)
elif numpy.issubdtype(type(x_arr), numpy.ndarray) == False:
if (type(x_arr) == list) or (numpy.issubdtype(type(x_arr), numpy.ndarray) == False):
x_arr = numpy.array(x_arr)
else:
pass
# check y_arr data type
if type(y_arr) == list:
y_arr = numpy.array(y_arr)
elif numpy.issubdtype(type(y_arr), numpy.ndarray) == False:
if (type(y_arr) == list) or (numpy.issubdtype(type(y_arr), numpy.ndarray) == False):
y_arr = numpy.array(y_arr)
else:
pass
Expand Down Expand Up @@ -451,7 +439,7 @@ def text_def(plot, df, ax, ci, hue, multiple, axis, text, sep, add, text_fontsiz
except:
raise Exception('Unknown text fontsize argument!')
else:
ax.annotate(f'{y_add}', xy=(x, y-max_y*0.03), ha='center', va='center')
ax.annotate(f'{y_add}', xy=(x, y-min_y*0.03), ha='center', va='center')
else:
pass
else:
Expand Down
17 changes: 17 additions & 0 deletions grplot/utils/check_data_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy
import pandas

def check_data_structure(df):
if type(df) == dict:
if any(isinstance(df[key], list) for key in df.keys()) == True:
out = 'dictionary-list'
elif any(isinstance(df[i], numpy.ndarray) for i in df.keys()):
out = 'dictionary-numpy.array'
else:
raise Exception('Unsupported dictionary sub data structure!')
elif type(df) == pandas.core.frame.DataFrame:
out = 'pandas dataframe'
else:
raise Exception('Unsupported data structure!')
return out

5 changes: 4 additions & 1 deletion grplot_seaborn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from .axisgrid import * # noqa: F401,F403
from .widgets import * # noqa: F401,F403
from .colors import xkcd_rgb, crayons # noqa: F401
from . import cm # noqa: F401
try:
from seaborn import cm # noqa: F401
except:
from . import cm # noqa: F401

# Capture the original matplotlib rcParams
import matplotlib as mpl
Expand Down
5 changes: 4 additions & 1 deletion grplot_seaborn/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import pandas as pd
from scipy.cluster import hierarchy

from . import cm
try:
from seaborn import cm # noqa: F401
except:
from . import cm # noqa: F401
from .axisgrid import Grid
from .utils import (
despine,
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

DISTNAME = "grplot"
VERSION = "0.12.1"
VERSION = "0.13.1"
MAINTAINER = "Ghiffary Rifqialdi"
MAINTAINER_EMAIL = "[email protected]"
DESCRIPTION = "grplot: lazy statistical data visualization"
Expand Down Expand Up @@ -40,6 +40,7 @@
"grplot.features.add.text_add",
"grplot.features.add.tick_add",
"grplot.features.dt",
"grplot.features.filter",
"grplot.features.font",
"grplot.features.legend",
"grplot.features.lim",
Expand Down

0 comments on commit acf2eda

Please sign in to comment.