<jupyter_start><jupyter_text>Seaborn: distplot<jupyter_code>from matplotlib import pyplot as plt
import seaborn as sns
cars = sns.load_dataset('mpg').dropna()

cars.shape
cars.head()
sns.set_style('white')<jupyter_output><empty_output><jupyter_text>Intro Visuals<jupyter_code>hp = cars.horsepower.sample(100, random_state=100)
hp
plt.rc('xtick', labelsize=14)
plt.rc('ytick', labelsize=14)
plt.figure(figsize=(8,5))
sns.distplot(hp, rug=True, kde=False, hist=False, rug_kws={'lw': 2})

sns.despine(left=True)
plt.xlim(0, 280)
plt.xlabel('')
plt.yticks([])
plt.tight_layout();
plt.figure(figsize=(8,5))
sns.distplot(hp, kde=False, hist_kws={'alpha': 1})

sns.despine(left=True)
plt.xlim(0, 280)
plt.xlabel('')
plt.yticks([])
plt.tight_layout();
plt.figure(figsize=(8,5))
sns.distplot(hp, hist=False, kde_kws={'lw': 5})

sns.despine(left=True)
plt.xlim(0, 280)
plt.xlabel('')
plt.yticks([])
plt.tight_layout();
plt.figure(figsize=(8,5))
sns.distplot(hp, rug=True, kde_kws={"lw": 5}, rug_kws={'lw': 2} )

sns.despine(left=True)
plt.xlim(0, 280)
plt.xlabel('')
plt.yticks([])
plt.tight_layout();<jupyter_output>/home/adarshanand67/anaconda3/lib/python3.9/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
/home/adarshanand67/anaconda3/lib/python3.9/site-packages/seaborn/distributions.py:2103: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
  warnings.warn(msg, FutureWarning)<jupyter_text>Basics<jupyter_code>cars.weight
sns.distplot(cars.weight);
sns.distplot(cars.weight, kde=False);
sns.distplot(cars.weight, hist=False, rug=True);<jupyter_output><empty_output><jupyter_text>Options  Bins<jupyter_code>sns.distplot(cars.weight, bins=5);  
sns.distplot(cars.weight, bins=[1500, 2000, 2500, 3500, 5200]);<jupyter_output><empty_output><jupyter_text>Fit<jupyter_code>from scipy.stats import skewnorm

sns.distplot(cars.weight, fit=skewnorm, kde=False);<jupyter_output><empty_output><jupyter_text>Kwargs  hist_kws<jupyter_code>sns.distplot(cars.weight, kde=False, hist_kws={'alpha': 1});
sns.distplot(cars.weight, kde=False, 
             hist_kws={'alpha': 1, 'histtype': 'stepfilled'});<jupyter_output><empty_output><jupyter_text>kde_kws<jupyter_code>sns.distplot(cars.weight, kde_kws={'lw': 5});
sns.kdeplot(cars.weight, lw=5);  
sns.distplot(cars.weight, kde_kws={'bw': 1000});<jupyter_output><empty_output><jupyter_text>rug_kws<jupyter_code>sns.distplot(cars.weight, rug=True, rug_kws={'height': 0.15});
sns.distplot(cars.weight, rug=True, 
             rug_kws={'height': 0.15, 'color': 'xkcd:navy'});<jupyter_output><empty_output><jupyter_text>Styled Distplots<jupyter_code>sns.set_style('white')

plt.figure(figsize=(8,5))
sns.distplot(cars.weight, 
             bins=20,
             kde_kws={"lw": 8, 'color':'xkcd:bluish green'},
             hist_kws={'alpha': 0.3, 'color':'gray'}
            )

sns.despine(left=True)
plt.xlabel('Weight (lbs)', fontsize=16, labelpad=15)
plt.yticks([])
plt.tight_layout()

plt.savefig('03dist_styleWeight_greenKDE.svg');
sns.set_style('white')

plt.figure(figsize=(8,5))
sns.distplot(cars.acceleration.sample(100, random_state=100), 
             rug=True,
             kde=False,
             hist_kws={'lw': 5, 
                       'linestyle': (0, (5, 1)),
                       'alpha': 1, 
                       'histtype':'step', 
                       'color':'xkcd:dark magenta'},
             rug_kws={'lw': 3,
                      'color':'xkcd:dark magenta'}
            )
sns.distplot(cars.acceleration.sample(100, random_state=100), 
             kde=False,
             hist_kws={'alpha': 0.1,
                       'histtype':'stepfilled', 
                       'color':'xkcd:dark magenta'},
            )

sns.despine(left=True)
plt.xlabel('')
plt.xticks([])
plt.yticks([])
plt.tight_layout()

plt.savefig('03dist_styleAcc_pink.svg');
import random
random.seed(11)

data = [random.gauss(2, 0.75) for _ in range(50)]
data.extend([random.gauss(-2, 0.75) for _ in range(50)])

sns.set_style('whitegrid')

plt.figure(figsize=(8,5))
sns.distplot(data, 
             rug=True,
             hist=False, 
             color='green',
             kde_kws={'lw':4, 'shade':True, 'bw':.5},
             rug_kws={'lw':2}
            )

sns.despine()
plt.xlabel('')
plt.tight_layout()

#plt.savefig('03dist_styleRand_greenKDErug.svg');
sns.set_style('darkgrid')

data = [random.gauss(2, 0.75) for _ in range(100)]
data.extend([random.gauss(-2, 0.75) for _ in range(50)])

plt.figure(figsize=(8,5))
sns.distplot(data, 
             hist_kws={'histtype': 'stepfilled', 
                       'alpha':0.7, 'color':'xkcd:carolina blue'},
             kde_kws={'lw':8,'color':'xkcd:navy'}
            )

sns.despine()
plt.xlabel('')
plt.tight_layout()

#plt.savefig('03dist_styleRand_carolina.svg');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17416715371127994, 'fraction_numerical': 0.03311903370348724, 'mean_word_length': 4.271047227926078, 'pattern_counts': {'":': 2, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '229096', 'license': 'MIT', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2006, 'n_words': 284, 'path': '03_distplot.ipynb', 'repo_name': 'AdarshAnand67/Seaborn-Complete', 'size': '5133'}