From cdeebac1f9780454b892ae6311a5f5f654df8d5d Mon Sep 17 00:00:00 2001 From: Mikko Kotila Date: Thu, 23 Apr 2020 14:14:00 +0300 Subject: [PATCH 1/5] test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b097e81..3f97b02 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ pip install astetik # TL;DR -## Why Astetik +## Why Astetik? Astetik takes the amazing potential of matplotlib and seaborn, and makes it available through single-line commands. While much of the lower level complexity is made invisible, some completely new features are added. Whatever is added is further taking away from the complexity of the visualizastion workflow. From 90b99af547cfb5088b016694c83c56f55d85a6cb Mon Sep 17 00:00:00 2001 From: Mikko Kotila Date: Sun, 10 May 2020 21:11:48 +0300 Subject: [PATCH 2/5] improved line graph --- astetik/plots/line.py | 70 +++++++++++++++++++++++++++++++++++------ astetik/style/legend.py | 2 +- astetik/style/style.py | 6 ++-- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/astetik/plots/line.py b/astetik/plots/line.py index a9a640e..3a6dee0 100644 --- a/astetik/plots/line.py +++ b/astetik/plots/line.py @@ -16,17 +16,24 @@ def line(data, x=None, y=None, + highlight_x=None, interval=False, interval_func=None, time_frame=None, dropna=False, median_line=False, drawstyle='default', - linestyle='solid', - linewidth=2, + linestyle=None, + linewidth=None, markerstyle=None, + smooth=None, legend_labels=None, + annotate_line_end=False, + annotate_text=None, + annotate_xy=(), + annotate_text_xy=(), palette='default', + alpha=1, style='astetik', dpi=72, title='', @@ -119,6 +126,8 @@ def line(data, Or use any cmap, seaborn or matplotlib color or palette code, or hex value. + alpha :: Color saturation (float) + style :: Use one of the three core styles: 'astetik' # white '538' # grey @@ -151,10 +160,9 @@ def line(data, ''' - # START OF PLOT SPECIFIC >>> + data = data.copy(deep=True) - if x == None: - x = list(data.columns.values) + # START OF PLOT SPECIFIC >>> if isinstance(x, list) is False: x = [x] @@ -168,13 +176,16 @@ def line(data, data[y] = range(len(data)) if interval != False: - data = data.copy(deep=True) data = multicol_transform(transform='interval', data=data, x=x, y=y, func=interval_func, freq=interval) + if smooth is not None: + + from scipy.ndimage import gaussian_filter1d + data[x] = data[x].apply(gaussian_filter1d, sigma=smooth) if markerstyle is None: markers = ["o", "+", "x", "|", "1", "8", "s", "p", @@ -185,6 +196,22 @@ def line(data, markers.append(markerstyle) # <<< END OF PLOT SPECIFIC + if linestyle is None: + linestyle = ['solid'] * lines + elif isinstance(linestyle, str): + linestyle = [linestyle] * lines + + if linewidth is None: + linewidth = [2] * lines + elif isinstance(linewidth, list) is False: + linewidth = [linewidth] * lines + + if highlight_x is not None: + linestyle = ['--'] * lines + linestyle[x.index(highlight_x)] = 'solid' + linewidth = [2] * lines + linewidth[x.index(highlight_x)] = 4 + # START OF HEADER >>> palette = _header(palette, style, n_colors=lines, dpi=dpi) # <<< END OF HEADER @@ -198,15 +225,38 @@ def line(data, data[x[i]], marker=markers[i], drawstyle=drawstyle, - linestyle=linestyle, + linestyle=linestyle[i], c=palette[i], - linewidth=linewidth, + linewidth=linewidth[i], markersize=7, - markeredgewidth=2, + markeredgewidth=1, mfc='white', rasterized=True, aa=True, - alpha=1) + alpha=alpha) + + if len(annotate_xy) > 0: + + ax.annotate(annotate_text, + xy=(annotate_xy[0], annotate_xy[1]), + xycoords='data', + xytext=(annotate_text_xy[0], annotate_text_xy[1]), + textcoords='axes fraction', + arrowprops=dict(facecolor='#888888', shrink=0.05), + horizontalalignment='right', + verticalalignment='top') + + if annotate_line_end: + + for i, col in enumerate(x): + + ax.annotate(col + ' ' + str(round(data[col][-1:].values[0], 2)), + xy=(45, data[col][-1:].values), + xytext=(6, data[col][-1:].values), + color=palette[i], + xycoords='data', + textcoords="offset points", + size=14, va="center") # SCALING if y_scale != None or x_scale != None: diff --git a/astetik/style/legend.py b/astetik/style/legend.py index 581f708..ff27be2 100644 --- a/astetik/style/legend.py +++ b/astetik/style/legend.py @@ -7,6 +7,6 @@ def _legend(x, legend, legend_labels, legend_position): x = legend_labels if len(legend_position) == 0: - plt.legend(x, loc=1, ncol=1, bbox_to_anchor=(1.35, 1.0)) + plt.legend(x, loc=1, ncol=1, bbox_to_anchor=(1.25, 1.0)) else: plt.legend(x, loc=legend_position[0], ncol=legend_position[1]) diff --git a/astetik/style/style.py b/astetik/style/style.py index e9e5fa4..d5d4b7c 100644 --- a/astetik/style/style.py +++ b/astetik/style/style.py @@ -18,9 +18,9 @@ def styles(dpi): style_dic = { # FONT - 'font.size': 12, - 'font.family': 'Verdana', - 'font.stretch': 'normal', + 'font.size': 14, + 'font.family': 'Verdana, Geneva, sans-serif', + 'font.stretch': 'semi-expanded', 'font.style': 'normal', 'font.variant': 'normal', 'font.weight': 'normal', From 6fe2a93a277feaf7464c86423eb0aea1032c7bb9 Mon Sep 17 00:00:00 2001 From: Mikko Kotila Date: Sun, 10 May 2020 21:15:55 +0300 Subject: [PATCH 3/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 25da256..a409c75 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ URL = 'http://mikkokotila.com' LICENSE = 'MIT' DOWNLOAD_URL = 'https://github.com/mikkokotila/pretty' -VERSION = '1.9.9' +VERSION = '1.10.0' try: from setuptools import setup From a029f2ce592a87ab7dc2f50ce3fb756bd3ef39cb Mon Sep 17 00:00:00 2001 From: Mikko Kotila Date: Mon, 11 May 2020 19:12:00 +0300 Subject: [PATCH 4/5] improved line annotation --- astetik/plots/line.py | 22 +++++++++++++++++----- astetik/style/titles.py | 3 +-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/astetik/plots/line.py b/astetik/plots/line.py index 3a6dee0..9d063ee 100644 --- a/astetik/plots/line.py +++ b/astetik/plots/line.py @@ -16,6 +16,7 @@ def line(data, x=None, y=None, + xtick_labels=None, highlight_x=None, interval=False, interval_func=None, @@ -242,7 +243,12 @@ def line(data, xycoords='data', xytext=(annotate_text_xy[0], annotate_text_xy[1]), textcoords='axes fraction', - arrowprops=dict(facecolor='#888888', shrink=0.05), + color='#888888', + size=15, + arrowprops=dict(facecolor='#888888', + shrink=0.05, + color='#888888', + lw=2), horizontalalignment='right', verticalalignment='top') @@ -251,13 +257,14 @@ def line(data, for i, col in enumerate(x): ax.annotate(col + ' ' + str(round(data[col][-1:].values[0], 2)), - xy=(45, data[col][-1:].values), + xy=(len(data[col]), data[col][-1:].values), xytext=(6, data[col][-1:].values), color=palette[i], xycoords='data', textcoords="offset points", - size=14, va="center") - + size=14, + va="center") + # SCALING if y_scale != None or x_scale != None: for i in range(lines): @@ -286,4 +293,9 @@ def line(data, _footer(p, x_label, y_label, save=save) _legend(x, legend, legend_labels, legend_position) - ax.xaxis.set_major_locator(ticker.MaxNLocator(nbins=8, integer=True)) + ax.xaxis.set_major_locator(ticker.MaxNLocator(nbins=5, integer=True)) + + if xtick_labels is not None: + _len_ = len(xtick_labels) + _picks_ = list(range(0, _len_, int(_len_ / 7))) + plt.xticks(ticks=_picks_, labels=xtick_labels[_picks_]) diff --git a/astetik/style/titles.py b/astetik/style/titles.py index fe2492c..134225d 100644 --- a/astetik/style/titles.py +++ b/astetik/style/titles.py @@ -33,11 +33,10 @@ def _titles(title, title = title.replace(' ', '\,') title = title.replace('_', '\_') - # NOTE: it's probably better to draw some lines... plt.title(r"$\bf{" + title + "}$" + '\n' + sub_title, loc=location, fontsize=fontsize, fontname=fontname, weight='normal', y=1.03, - color="grey"); + color="grey"); \ No newline at end of file From d5e822caaf3c8a3234cc8ea0f5d323a4f0dfa878 Mon Sep 17 00:00:00 2001 From: Mikko Kotila Date: Mon, 11 May 2020 22:40:37 +0300 Subject: [PATCH 5/5] Update __init__.py --- astetik/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/astetik/__init__.py b/astetik/__init__.py index 4c276e1..f36697d 100755 --- a/astetik/__init__.py +++ b/astetik/__init__.py @@ -51,5 +51,3 @@ del utils except: pass - -__version__ = "1.9.9"