In [1]:
from ahh import exp, vis, era
import matplotlib.pyplot as plt
import os
import pandas as pd
import numpy as np

In [2]:
OUTPUT_DIR = 'output'
SAVE_FMT = 'plot_{pltype}_{testname}_dt.png'

def join_out(pltype, testname):
    return os.path.join(OUTPUT_DIR,
                        SAVE_FMT.format(pltype=pltype,
                                        testname=testname))
xy_len = 15
# x = exp.arr_1d(periods=xy_len)
x = pd.date_range('2016-01-01', periods=xy_len, freq='1Y')
y = exp.arr_1d(periods=xy_len, y=True) / 10

In [3]:
testname = 'rows_cols_pos'

vis_dict = dict(close=False, rows=2, cols=2, ylabel='test')
vis.plot_line(x, y, save=join_out('line', testname), pos=1, **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), pos=2, **vis_dict)
ax = vis.plot_scatter(x, y, save=join_out('scatter', testname), pos=3, **vis_dict)
vis.set_labels(ax, suptitle=True, title='hello')


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf35e27908>
Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1efb62b0>
Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1db650f0>

In [4]:
testname = 'sidebars'

vis_dict = dict(close=False, sidebar_count=3)
vis.plot_bar(x, y, save=join_out('bar', testname), label='bar', **vis_dict)
vis.plot_bar(x, y / 2, save=join_out('bar', testname), label='bar', color='blue', sidebar_pos=2, **vis_dict)
vis.plot_bar(x, y * 1.5, save=join_out('bar', testname), label='bar', color='green', sidebar_pos=3, **vis_dict)


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19fea438>
/home/solactus/anaconda3/lib/python3.5/site-packages/matplotlib/cbook/deprecation.py:106: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19fea438>
Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19fea438>

In [5]:
testname = 'label_line'

vis_dict = dict(close=False, label_inline=True, figsize='na')
vis.set_figsize()
ax = vis.plot_line(x, y, save=join_out('line', testname), label='red line', **vis_dict)
ax = vis.plot_line(x, y * -1, save=join_out('line', testname), label='blue line', color='blue', **vis_dict)


Out[5]:
<matplotlib.figure.Figure at 0x7fdf1a0558d0>
/home/solactus/anaconda3/lib/python3.5/site-packages/matplotlib/cbook/deprecation.py:106: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)

In [6]:
testname = 'inherit'

vis_dict = dict(close=False, figsize='na')
vis.set_figsize()

vis.plot_bar(x, y * 5, save=join_out('bar', testname), title='test title', **vis_dict)
vis.plot_scatter(x, y * 25, save=join_out('scatter', testname), xlabel='test xlabel', **vis_dict)
vis.plot_line(x, y * -2, save=join_out('line', testname), **vis_dict)


Out[6]:
<matplotlib.figure.Figure at 0x7fdf1dd919b0>
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dd91978>
/home/solactus/anaconda3/lib/python3.5/site-packages/matplotlib/cbook/deprecation.py:106: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dd91978>
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dd91978>

In [7]:
testname = 'twinx'

vis_dict = dict(close=False)
ax2 = vis.plot_line(x, y, save=join_out('line', testname), **vis_dict)
ax1 = vis.plot_scatter(x, y * 2, save=join_out('scatter', testname), color='red', figsize='na', **vis_dict)
ax1 = vis.plot_bar(x, y, save=join_out('bar', testname), twinx=ax2, color='blue', **vis_dict)


/home/solactus/anaconda3/lib/python3.5/site-packages/matplotlib/cbook/deprecation.py:106: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)
<matplotlib.figure.Figure at 0x7fdf1dc05438>

In [8]:
vis.plot_bar(x, y, align='edge')
vis.plot_bar(x, y, align='center')


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1a0510f0>
Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c78a978>

In [9]:
testname = 'scale_scatter'

vis_dict = dict(close=False)
ax = vis.plot_scatter(x, y, save=join_out('scatter_size', testname), c=y, 
                      cbar=True, xlabel='x', **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter_color', testname), s=y * 10, **vis_dict)


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1ccb0160>

In [10]:
testname = 'figsize_dpi'

vis_dict = dict(close=False, dpi=75)
vis.plot_line(x, y, figsize=(7, 3), save=join_out('line', testname), **vis_dict)
vis.plot_bar(x, y, figsize=(3, 7), save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(x, y, figsize=(5, 5), save=join_out('scatter', testname), **vis_dict)


Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d10a4a8>
Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d4c6898>
Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d180908>

In [11]:
testname = 'xtext'
xtext = ['1', '2', 'Three', 'Four', 'Five', 'Sx', 'Sv', 'Eg', 'Ni', 'Ten', '11', 'Orange'] + ['fill'] * (xy_len - 12)

vis_dict = dict(close=False, figsize=(20, 5))
vis.plot_line(xtext, y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(xtext, y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(xtext, y, save=join_out('scatter', testname), **vis_dict)


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c1b0470>
Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c299e10>
Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d4ac518>

In [12]:
testname = 'x2y'

vis_dict = dict(close=False,)
vis.plot_line(y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(y, save=join_out('scatter', testname), **vis_dict)


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1cf62400>
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1ededd30>
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19aa97f0>

In [13]:
testname = 'xlim'

vis_dict = dict(close=False)
vis.plot_line(x, y, save=join_out('line', testname), xlim=(0, 10), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), xlim=(0, 50), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), xlim=(-30, 30), **vis_dict)


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19b8e9e8>
Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c5f7160>
Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c5ffc88>

In [14]:
testname = 'xlim'

vis_dict = dict(close=False)
ax = vis.plot_line(x, y, save=join_out('line', testname), xlim=('2016-02-28', '2016-03-28'), **vis_dict)
ax = vis.plot_bar(x, y, save=join_out('bar', testname), xlim=('2016-02-28', '2016-04-28'), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), xlim=('2015-02-28', '2015-05-28'), **vis_dict)


Unable to inherit xlim!
Unable to inherit xlim!
Unable to inherit xlim!
Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1e2d0cc0>

In [15]:
testname = 'ylim'

vis_dict = dict(close=False)
vis.plot_line(x, y, save=join_out('line', testname), ylim=(-10, 20), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), ylim=(0, 50), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), ylim=(-30, 30), **vis_dict)


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d861588>
Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dcad828>
Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1eaea9b0>

In [16]:
testname = 'cumsum'

vis_dict = dict(close=False, cumsum=True)
vis.plot_line(x, y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), **vis_dict)


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c664fd0>
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c63e208>
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c0010f0>

In [17]:
testname = 'norm'

vis_dict = dict(close=False, norm=True)
vis.plot_line(x, y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), **vis_dict)


Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1bd21828>
Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c71a6a0>
Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d541160>

In [18]:
testname = 'anom'

vis_dict = dict(close=False, anom=True)
vis.plot_line(x, y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), **vis_dict)


Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1cb7d7f0>
Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1cb33710>
Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1bffc5f8>

In [19]:
testname = 'norm_anom'

vis_dict = dict(close=False, norm_anom=True)
vis.plot_line(x, y, save=join_out('line', testname), **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), **vis_dict)


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dcf2438>
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1eafddd8>
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1db90400>

In [20]:
testname = 'stats'

vis_dict = dict(close=False)
vis.plot_line(x, y, save=join_out('line', testname), stats='top center', **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), stats='bottom left', **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), stats='center bottom', **vis_dict)


Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dd127b8>
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf19d03a90>
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1a2f8080>

In [21]:
testname = 'style'

vis_dict = dict(close=False, alpha=0.1, label='test')
vis.plot_bar(x, y, save=join_out('bar', testname), width=1, facecolor='blue', edgecolor='red', linewidth=15,
             matchcolor=False, linestyle='--', **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), facecolor='green', edgecolor='purple',
                 size=500, matchcolor=False, **vis_dict)
vis.plot_line(x, y, save=join_out('line', testname), linewidth=10, linestyle='--', marker='o', markersize=20, **vis_dict)


Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1cda70b8>
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1e8db978>
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dd70668>

In [22]:
# testname = 'projection' ## NEED TESTING

# vis_dict = dict(close=False)
# vis.plot_line(y, save=join_out('line', testname), xlim=(0, 10), **vis_dict)
# vis.plot_bar(y, save=join_out('bar', testname), xlim=(0, 50), **vis_dict)
# vis.plot_scatter(y, save=join_out('scatter', testname), xlim=(-30, 30), **vis_dict)

In [23]:
testname = 'scale_invert'

vis_dict = dict(close=False)
ax = vis.plot_line(x, y, save=join_out('line', testname), xscale='log', yinvert=True, **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), yscale='log', xinvert=True, **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), xinvert=True, yinvert=True, **vis_dict)


/home/solactus/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_base.py:3245: UserWarning: Attempted to set non-positive ylimits for log-scale axis; invalid limits will be ignored.
  'Attempted to set non-positive ylimits for log-scale axis; '
Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dc83828>
Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1d1fc208>

In [24]:
testname = 'labels' #, histogram

vis_dict = dict(close=False)
vis.plot_line(x, y, save=join_out('line', testname), xlabel='xlabel', **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), ylabel='ylabel', **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), title='title', title_pad=1.15, **vis_dict)


Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1e3db5f8>
Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1bd8d048>
Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c419860>

In [25]:
testname = 'legend'

vis_dict = dict(close=False)
vis.plot_line(x, y, save=join_out('line', testname), label='line', **vis_dict)
vis.plot_bar(x, y, save=join_out('bar', testname), label='bar', legend='top left' , **vis_dict)
vis.plot_scatter(x, y, save=join_out('scatter', testname), label='scatter', legend='center' , **vis_dict)


Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1c4b3710>
Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dcb10f0>
Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dbc5b38>

In [26]:
testname = 'share'

vis_dict = dict(close=False, rows=2, cols=2, title='test', ylabel='test')
ax = vis.plot_scatter(x, y, save=join_out('scatter', testname), pos=1, **vis_dict)
ax2=vis.plot_bar(x, y, save=join_out('bar', testname), sharey=ax, pos=2, **vis_dict)
vis.plot_line(x, y, save=join_out('line', testname), sharex=ax, pos=3, **vis_dict)
vis.plot_line(x, y, save=join_out('line', testname), sharex=ax2, pos=4, **vis_dict)


Out[26]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1ee81550>
Out[26]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdf1dfb5c18>

In [27]:
vis_dict = dict(close=False)

fruits = ['banana', 'banana', 'apple', 'orange', 'orange', 'orange', 'avocado', 'avocado', 'pear', 'cloud'] + ['test'] * 10
vis.plot_histogram(fruits, save=join_out('bar', testname), **vis_dict)
vis.plot_histogram(fruits, ptype='line', save=join_out('line', testname), color='orange', **vis_dict)
vis.plot_histogram(fruits, ptype='scatter', save=join_out('scatter', testname), color='blue', **vis_dict)



In [ ]: