<jupyter_start><jupyter_text>9.4 Plotting with seaborn and pandas P II  Scatter or Point Plots<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

macro = pd.read_csv(r'D:/macrodata.csv')
data = macro[['cpi', 'm1', 'tbilrate', 'unemp']]
trans_data = np.log(data).diff().dropna()
trans_data.head()<jupyter_output><empty_output><jupyter_text>We can then use seaborn’s regplot method, which makes a scatter plot and fits a lin‐ear regression line<jupyter_code>plt.title('Changes in log %s versus log %s' % ('m1', 'unemp'))
sns.regplot('m1', 'unemp', data=trans_data)<jupyter_output><empty_output><jupyter_text>In exploratory data analysis it’s helpful to be able to look at all the scatter plots amonga group of variables; this is known as a pairs plot or scatter plot matrix. Making such aplot  from  scratch  is  a  bit  of  work,  so  seaborn  has  a  convenient  pairplot  function,which  supports  placing  histograms  or  density  estimates  of  each  variable  along  thediagonal<jupyter_code>sns.pairplot(trans_data, diag_kind='kde', plot_kws={'alpha': 0.2})<jupyter_output><empty_output><jupyter_text>Facet Grids and Categorical Data What about datasets where we have additional grouping dimensions? One way to vis‐ualize data with many categorical variables is to use a facet grid. Seaborn has a usefulbuilt-in function factorplot that simplifies making many kinds of faceted plots<jupyter_code>tips=pd.read_csv(r'D:/tips.csv')
tips.head()
tips['tip_pct']=(tips.tip/(tips.tip+tips.total_bill))
tips.head()
sns.factorplot(x='day', y='tip_pct', hue='time', col='smoker',
               kind='bar', data=tips[tips.tip_pct < 1])<jupyter_output>E:\Anaconda\lib\site-packages\seaborn\categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
  warnings.warn(msg)<jupyter_text>Instead  of  grouping  by  'time'  by  different  bar  colors  within  a  facet,  we  can  alsoexpand the facet grid by adding one row per time value<jupyter_code>sns.factorplot(x='day', y='tip_pct', row='time',
               col='smoker',
               kind='bar', data=tips[tips.tip_pct < 1])<jupyter_output>E:\Anaconda\lib\site-packages\seaborn\categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
  warnings.warn(msg)<jupyter_text>factorplot supports other plot types that may be useful depending on what you aretrying to display.<jupyter_code>sns.factorplot(x='tip_pct', y='day', kind='box',
               data=tips[tips.tip_pct < 0.5])<jupyter_output>E:\Anaconda\lib\site-packages\seaborn\categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
  warnings.warn(msg)
{'fraction_non_alphanumeric': 0.11142061281337047, 'fraction_numerical': 0.007118539151965335, 'mean_word_length': 5.203454894433781, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 22, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '546235', 'license': 'MIT', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1079, 'n_words': 338, 'path': 'Python-For-Data-Analysis/Chapter 9 Data Visualization/9.4 Plotting with seaborn and pandas P II.ipynb', 'repo_name': 'insomniac-klutz/Data-Science-Referentica', 'size': '3231'}