<jupyter_start><jupyter_text>--- Introducing `LazyPlot`  .. tip:: this is a test whether we can insert Tip-blocks in a notebook Sometimes it's a bit cumbersome to go through all matplotlib motions such as intiating the figure, adding labels, and such when you just want to quickly visualize your data. This class is intended to do just that. Make the same plots in a whole lot less lines. I tried to include as many functionalities as possible without overcomplicating the process too much. Below are a few examples of how to use this class.<jupyter_code>%reload_ext autoreload
%autoreload 2
# imports
from linescanning import plotting, utils
import warnings
import os
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

warnings.simplefilter('ignore')
opj = os.path.join<jupyter_output><empty_output><jupyter_text>Create random timeseries with `linescanning.utils.random_timeseries`<jupyter_code>print(utils.random_timeseries.__doc__)<jupyter_output>random_timeseries

    Create a random timecourse by multiplying an intercept with a random Gaussian distribution.

    Parameters
    ----------
    intercept: float
        starting point of timecourse
    volatility: float
        this factor is multiplied with the Gaussian distribution before multiplied with the intercept
    nr: int
        length of timecourse 

    Returns
    ----------
    numpy.ndarray
        array of length `nr`

    Example
    ----------
    >>> from linescanning import utils
    >>> ts = utils.random_timeseries(1.2, 0.5, 100)

    Notes
    ----------
    Source: https://stackoverflow.com/questions/67977231/how-to-generate-random-time-series-data-with-noise-in-python-3<jupyter_text>Plot them regularly<jupyter_code>ts = utils.random_timeseries(1.2, 0.0, 100)
ts1 = utils.random_timeseries(1.2, 0.3, 100)
ts2 = utils.random_timeseries(1.2, 0.5, 100)
ts3 = utils.random_timeseries(1.2, 0.8, 100)
ts4 = utils.random_timeseries(1.2, 1, 100)
print(ts.shape)

fig,axs = plt.subplots(figsize=(20,5))
axs.plot(ts)
axs.plot(ts1)
axs.plot(ts2)
axs.plot(ts3)
axs.plot(ts4)
sns.despine(offset=10)<jupyter_output>(100,)<jupyter_text>Use `LazyPlot` to plot a single timeseries<jupyter_code>utils.LazyPlot(ts2, figsize=(20, 5))<jupyter_output><empty_output><jupyter_text>Use `LazyPlot` to plot multiply timeseries<jupyter_code>plotting.LazyPlot([ts, ts1, ts2, ts3, ts4], 
                  figsize=(20, 5), 
                  save_as="/mnt/d/FSL/shared/spinoza/programs/project_repos/PlayGround/results/test_LazyPlot.pdf",
                  labels=['vol=0', 'vol=0.3', 'vol=0.5', 'vol=0.8', 'vol=1.0'])<jupyter_output><empty_output><jupyter_text>Add horizontal line<jupyter_code>hline = {'pos': 1.2, 'color': 'k', 'lw': 0.5, 'ls': '--'}
plotting.LazyPlot(ts2, figsize=(20, 5), add_hline=hline)<jupyter_output><empty_output><jupyter_text>Add vertical line<jupyter_code>vline = {'pos': 1.2, 'color': 'k', 'lw': 0.5, 'ls': '--'}
plotting.LazyPlot(ts2, figsize=(20, 5), add_vline=vline)<jupyter_output><empty_output><jupyter_text>Add shaded error<jupyter_code>from scipy.stats import sem
stack = np.hstack((ts1[...,np.newaxis],ts2[...,np.newaxis],ts4[...,np.newaxis]))
avg = stack.mean(axis=-1)
err = sem(stack, axis=-1)
plotting.LazyPlot(avg, figsize=(20, 5), error=err)<jupyter_output><empty_output><jupyter_text>Subplotting with gridspec<jupyter_code># initialize the figure. Figsize only specified in plt.figure, not in LazyPlot
fig = plt.figure(constrained_layout=True, figsize=(30,10))

# specify the grid
gs = fig.add_gridspec(2,2)

# collect fake timecourses in list so we can index them
timecourses = [ts1, ts2, ts3, ts4]

for ii in range(4):

    # add subplot to figure on axis in gridspec
    ax = fig.add_subplot(gs[ii])
    
    # give the axis to LazyPlot
    plotting.LazyPlot(timecourses[ii],
                      axs=ax,
                      set_xlim_zero=True,
                      title=f"Timecourse {ii+1}",
                      font_size=16)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12775551102204408, 'fraction_numerical': 0.031312625250501, 'mean_word_length': 4.016331658291457, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '291880', 'license': 'MIT', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1381, 'n_words': 337, 'path': 'doc/source/examples/lazyplot.ipynb', 'repo_name': 'gjheij/linescanning', 'size': '3992'}