<jupyter_start><jupyter_text>Seaborn - grids and customization**ToC** - [Pairgrids](Pairgrids) - [lmplot() for scatter and regression per category](lmplot()-for-scatter-and-regression-per-category) - [FacetGrid](FacetGrid) - [Customizing grids](Customizing-grids) - [Fig and font size](Fig-and-font-size)<jupyter_code>import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
iris= sns.load_dataset('iris')
iris.head()<jupyter_output><empty_output><jupyter_text>PairgridsPairgrid is similar to `pairplot`, except, it returns back an empty grid that you can fill up with desired plots later. Refresher on [pariplot](https://atmamani.github.io/talks/cheatsheets/seaborn_cheat_sheet_1.htmlPlotting-dist-of-all-variables)<jupyter_code>grd = sns.PairGrid(data=iris)

#then you can assign what you want plotted for diagonal, above diagonal, below diagonal.
# when mapping, pass just function pointers, dont call the function itself.
grd.map_diag(sns.distplot)
grd.map_upper(plt.scatter)
grd.map_lower(sns.kdeplot)<jupyter_output><empty_output><jupyter_text>`lmplot()` for scatter and regression per categorySometimes, you need to do a `joinplot()` but split it by some categorical column. You can custom build it using `FacetGrid` shown in next section. However, seaborn provides a convenience function called `lmplot()`. Note: In previous pages, you created `lmplots()` for just 2 columns without any category.<jupyter_code>pgrid = sns.lmplot(x='min_season', y='min_pressure_merged', 
                   col='any_basin', # the column by which you need to split - needs to be categorical
                   data=set1, 
                   col_wrap=3, # number of columns per row
                   sharex=False, sharey=False, # will repeat ticks, coords for each plot
                   line_kws={'color':'green'} # symbol for regression line
                  )<jupyter_output><empty_output><jupyter_text>FacetGridDuring EDA, you want to find the distribution of data by sub-categories, sub-conditions. You can do so by building FacetGrids. As it means, you get a grid for every facet of the data.<jupyter_code>#load tips data
tips = sns.load_dataset('tips')
tips.head()<jupyter_output><empty_output><jupyter_text>Suppose we want to visualize `total_bill` by time of day and wheather or not it was a smoker. You need to filter data out then make dist plots. YOu can do all of that in 1 step with `FacetGrid`s.<jupyter_code>#for each unique value in `time` you get a row and 
# each unique value in `smoker` you get a col
fg = sns.FacetGrid(data=tips, row='time', col='smoker')

#now map a plot for each of the grid
fg.map(sns.distplot, 'total_bill')<jupyter_output><empty_output><jupyter_text>Customizing gridsIf you dont like the pale blue background of seaborn plots, you can modify that with `set_style`.Note: Using set_style() will control the appearance for the entire notebook and all future plots<jupyter_code>sns.set_style(style='ticks') #ticks, white, dark, darkgrid, whitegrid
#redraw the facet grid from above
fg = sns.FacetGrid(data=tips, row='time', col='smoker')

#now map a plot for each of the grid
fg.map(sns.distplot, 'total_bill')<jupyter_output><empty_output><jupyter_text>Fig and font sizeYou can use matplotlib `figsize` but have to specify that as a context as well.<jupyter_code>plt.figure(figsize=(5,5)) #generate a fig, sns will piggyback this with the plot
sns.distplot(tips['total_bill'])<jupyter_output><empty_output><jupyter_text>Using seaborn contextYou can use the `set_context()` to pick sizing templates<jupyter_code>sns.set_context(context='poster', font_scale=0.8)
# valid contexts = paper, notebook, talk, poster - 
# with notebook being 1:1 and paper being smaller and poster being largest

#draw the facet grid
fg = sns.FacetGrid(data=tips, row='smoker', col='time')
fg.map(sns.distplot, 'total_bill')<jupyter_output><empty_output><jupyter_text>Another way to set the size is to access the `fig` handle direclty<jupyter_code>#draw the facet grid
fg = sns.FacetGrid(data=tips, row='smoker', col='time')
#set the size
fg.fig.set_size_inches(w=10, h=10)
#plot the fig
fg.map(sns.distplot, 'total_bill')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10174766578884367, 'fraction_numerical': 0.0035910940866650705, 'mean_word_length': 5.349544072948328, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '564555', 'license': 'MIT', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1350, 'n_words': 434, 'path': 'python_crash_course/seaborn_cheat_sheet_4.ipynb', 'repo_name': 'AtmaMani/pyChakras', 'size': '4177'}