Skip to content

Instantly share code, notes, and snippets.

@ksv-muralidhar
Last active February 16, 2021 12:45

Revisions

  1. ksv-muralidhar revised this gist Feb 16, 2021. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions hist_3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import pandas as pd
    np.random.seed(11)
    norm_dist = pd.Series(np.random.randn(1000))
    q1 = norm_dist.quantile(0.25)
    q3 = norm_dist.quantile(0.75)
    iqr = q3 - q1
    bin_width = (2 * iqr) / (len(norm_dist) ** (1 / 3))
    bin_count = int(np.ceil((norm_dist.max() - norm_dist.min()) / bin_width))
    fig = plt.figure(figsize=(7,7))
    sns.histplot(x=norm_dist,bins=bin_count)
    plt.title(f'bins = {bin_count}')
  2. ksv-muralidhar revised this gist Feb 16, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions hist_2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    np.random.seed(11)
    norm_dist = np.random.randn(1000)
    bin_count = int(np.ceil(np.log2(len(norm_dist))) + 1)
    fig = plt.figure(figsize=(7,7))
    sns.histplot(x=norm_dist,bins=bin_count)
    plt.title(f'bins = {bin_count}')
  3. ksv-muralidhar revised this gist Feb 16, 2021. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions hist_1.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,11 @@
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns

    fig,ax = plt.subplots(2,3,figsize=(15,10))
    row = col = 0
    np.random.seed(11)
    norm_dist = np.random.randn(1000)
    for n,i in enumerate(np.linspace(5,100,6)):
    if (n>0) & (n%3==0):
    row += 1
    col = 0
    sns.histplot(x=np.random.randn(100),ax=ax[row,col])
    sns.histplot(x=norm_dist,bins=int(i),ax=ax[row,col])
    ax[row,col].set_title(f'bins = {int(i)}')
    col += 1
  4. ksv-muralidhar revised this gist Feb 16, 2021. No changes.
  5. ksv-muralidhar created this gist Feb 16, 2021.
    13 changes: 13 additions & 0 deletions hist_1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns

    fig,ax = plt.subplots(2,3,figsize=(15,10))
    row = col = 0
    for n,i in enumerate(np.linspace(5,100,6)):
    if (n>0) & (n%3==0):
    row += 1
    col = 0
    sns.histplot(x=np.random.randn(100),ax=ax[row,col])
    ax[row,col].set_title(f'bins = {int(i)}')
    col += 1