plotting

Set of functions and classes to make plotting easier

source

plot_timeseries


def plot_timeseries(
    tseries:Series, # one of several np.Series with DataTimeIndex
    ax:Optional=None, # axis to plot
    add_legend:bool=False, # add legend to plot, when True
)->None:
df = load_test_df()
plot_timeseries(df.Low, df.Close, df.High, add_legend=True)


source

plot_two_color_line


def plot_two_color_line(
    s:Series, # Data to plot as a pd.Series with DateTimeIndex
    cond:pandas.Series | numpy.ndarray, # boolean condition defining the colors to apply (same length as s)
    cond_labels:tuple=('Up', 'Down'), # labels for the condition to be used in the legend
    ax:matplotlib.axes._axes.Axes | None=None, # ax where to plot; if None, a new figure and ax will be created and shown
    linestyle:str='-', # '-' or 'solid'; '--' or 'dashed'; ':' or 'dotted'; '-.' or 'dashdot'
    figsize:tuple=(10, 6), colors:tuple=('#0D8821', '#D13F05')
):
df = load_test_df()
df['R'] = df.Close.pct_change()

cond = df['R'] > 0
plot_two_color_line(df['Close'], cond)

It is also possible to add a conditional line to an existing axes

df = load_test_df()
df['R'] = df.Close.pct_change()
cond = df['R'] > 0

fig, ax = plt.subplots(figsize=(10, 6))
plot_two_color_line(df['Close'], cond, ax=ax)
plot_two_color_line(df['Open'], cond, ax=ax, linestyle=':')
plot_two_color_line(df['High'], cond, ax=ax, linestyle='--')
plot_two_color_line(df['Low'], cond, ax=ax, linestyle='-.')
plt.show()


source

hist_timeseries


def hist_timeseries(
    tseries:Series, ax:Optional=None
)->None:
hist_timeseries(df.High)


source

plot_acfs


def plot_acfs(
    tseries:VAR_POSITIONAL, incl_lag0:bool=False, alpha:float=0.05, ax:NoneType=None
):
plot_acfs(df.Close, df.High)


source

normal_probability_plot


def normal_probability_plot(
    tseries:VAR_POSITIONAL, ax:NoneType=None
):
normal_probability_plot(df.Close.pct_change().dropna(), df.High.pct_change().dropna())