<jupyter_start><jupyter_text>Normal Distribution Plot by name from pandas dataframe This is a level 1 heading This is a level 2 heading<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline

np.random.seed([3,1415])
df = pd.DataFrame(dict(
        Name='<NAME>'.split() * 100,
        Seconds=np.random.randint(4000, 5000, 400)
    ))

df['Zscore'] = df.groupby('Name').Seconds.apply(lambda x: x.div(x.mean()))

df.groupby('Name').Zscore.plot.kde()

# split out plots
g = df.groupby('Name').Zscore
n = g.ngroups
print(n, g)
fig, axes = plt.subplots(n // 2, 2, figsize=(6, 6), sharex=True, sharey=True)
for i, (name, group) in enumerate(g):
    r, c = i // 2, i % 2
    group.plot.kde(title=name, ax=axes[r, c])
fig.tight_layout()


# kde + hist
g = df.groupby('Name').Zscore
n = g.ngroups
fig, axes = plt.subplots(n // 2, 2, figsize=(6, 6), sharex=True, sharey=True)
for i, (name, group) in enumerate(g):
    r, c = i // 2, i % 2
    a1 = axes[r, c]
    a2 = a1.twinx()
    group.plot.hist(ax=a2, alpha=.3)
    group.plot.kde(title=name, ax=a1, c='r')
fig.tight_layout()

# Plotting a dataframe as both a 'hist' and 'kde' on the same plot
import pandas as pd
import numpy as np


np.random.seed([3,1415])
df = pd.DataFrame(np.random.randn(100, 2), columns=list('ab'))

ax = df.a.plot(kind='hist')
df.a.plot(kind='kde', ax=ax, secondary_y=True)

ax1 = plt.subplot2grid((2,3), (0,0))

np.random.seed([3,1415])
df = pd.DataFrame(np.random.randn(100, 2), columns=list('ab'))

df.a.plot(kind='hist', ax=ax1)
df.a.plot(kind='kde', ax=ax1, secondary_y=True)

# Prior proposed solutions had KDE plot appear a little "shifted up" for me. seaborn.distplot accurately lined up zeros between hist and kde plots
import seaborn as sns
sns.distplot(df.a)

import matplotlib.pyplot as plt
def annotate_axes(fig):
    for i, ax in enumerate(fig.axes):
        ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
        ax.tick_params(labelbottom=False, labelleft=False)


fig = plt.figure()
ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3)
ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
ax4 = plt.subplot2grid((3, 3), (2, 0))
ax5 = plt.subplot2grid((3, 3), (2, 1))

annotate_axes(fig)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17872523686477174, 'fraction_numerical': 0.044358311800172266, 'mean_word_length': 4.243792325056433, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '561778', 'license': 'MIT', 'n_tokens_mistral': 1020, 'n_tokens_neox': 950, 'n_words': 241, 'path': 'testing/examples/Normal Distribution Plot by name from pandas dataframe.ipynb', 'repo_name': 'pchaos/quanttesting', 'size': '2336'}