import seaborn as sns
penguins = sns.load_dataset("penguins")
penguins
# Axes-level
sns.histplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c2e7d4850>
# Figure-level
sns.displot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
<seaborn.axisgrid.FacetGrid at 0x7f8c2e4bd990>
# Multiples figuras (Figure-level)
sns.displot(data=penguins, x="flipper_length_mm", hue="species", col="species")
<seaborn.axisgrid.FacetGrid at 0x7f8c24eba390>
# Axis level
import matplotlib.pyplot as plt
f, axs = plt.subplots(1, 2, figsize=(8, 4), gridspec_kw=dict(width_ratios=[4, 3]))
sns.scatterplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species", ax=axs[0])
sns.histplot(data=penguins, x="species", hue="species", shrink=.8, alpha=.8, legend=False, ax=axs[1])
f.tight_layout()
# Figure-level
tips = sns.load_dataset("tips")
g = sns.relplot(data=tips, x="total_bill", y="tip")
# Lineplot
flights = sns.load_dataset("flights")
flights.head()
year | month | passengers | |
---|---|---|---|
0 | 1949 | Jan | 112 |
1 | 1949 | Feb | 118 |
2 | 1949 | Mar | 132 |
3 | 1949 | Apr | 129 |
4 | 1949 | May | 121 |
# Axis-level
may_flights = flights.query("month == 'May'")
sns.lineplot(data=may_flights, x="year", y="passengers")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c249df3d0>
# Axis-level
flights_wide = flights.pivot("year", "month", "passengers")
flights_wide.head()
sns.lineplot(data=flights_wide)
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c24cec190>
tips = sns.load_dataset("tips")
tips.head()
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
# Scatterplot
sns.scatterplot(data=tips, x="total_bill", y="tip")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c2482f150>
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c247fc390>
# Barplot
import seaborn as sns
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.barplot(x="day", y="total_bill", data=tips)
sns.barplot(x="day", y="total_bill", hue="sex", data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c246fea50>
# Histograma
penguins = sns.load_dataset("penguins")
# Axis-level
sns.histplot(data=penguins, x="flipper_length_mm")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c24669090>
# Axis-level
sns.histplot(data=penguins, x="flipper_length_mm", hue="species")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c245809d0>
import seaborn as sns
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
# Axis-level
ax = sns.boxplot(x=tips["total_bill"])
# Axis-level
ax = sns.boxplot(x="day", y="total_bill", data=tips)
from google.colab import drive
import os
drive.mount('/content/gdrive')
%cd '/content/gdrive/MyDrive/'
Mounted at /content/gdrive /content/gdrive/MyDrive
import pandas as pd
df_lluvias = pd.read_csv('pune_1965_to_2002.csv')
df_lluvias.head()
Year | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1965 | 0.029 | 0.069 | 0.000 | 21.667 | 17.859 | 102.111 | 606.071 | 402.521 | 69.511 | 5.249 | 16.232 | 22.075 |
1 | 1966 | 0.905 | 0.000 | 0.000 | 2.981 | 63.008 | 94.088 | 481.942 | 59.386 | 150.624 | 1.308 | 41.214 | 4.132 |
2 | 1967 | 0.248 | 3.390 | 1.320 | 13.482 | 11.116 | 251.314 | 780.006 | 181.069 | 183.757 | 50.404 | 8.393 | 37.685 |
3 | 1968 | 0.318 | 3.035 | 1.704 | 23.307 | 7.441 | 179.872 | 379.354 | 171.979 | 219.884 | 73.997 | 23.326 | 2.020 |
4 | 1969 | 0.248 | 2.524 | 0.334 | 4.569 | 6.213 | 393.682 | 678.354 | 397.335 | 205.413 | 24.014 | 24.385 | 1.951 |
df_lluvias.index = df_lluvias['Year']
df_lluvias = df_lluvias.drop('Year', axis='columns')
df_lluvias
Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Year | ||||||||||||
1965 | 0.029 | 0.069 | 0.000 | 21.667 | 17.859 | 102.111 | 606.071 | 402.521 | 69.511 | 5.249 | 16.232 | 22.075 |
1966 | 0.905 | 0.000 | 0.000 | 2.981 | 63.008 | 94.088 | 481.942 | 59.386 | 150.624 | 1.308 | 41.214 | 4.132 |
1967 | 0.248 | 3.390 | 1.320 | 13.482 | 11.116 | 251.314 | 780.006 | 181.069 | 183.757 | 50.404 | 8.393 | 37.685 |
1968 | 0.318 | 3.035 | 1.704 | 23.307 | 7.441 | 179.872 | 379.354 | 171.979 | 219.884 | 73.997 | 23.326 | 2.020 |
1969 | 0.248 | 2.524 | 0.334 | 4.569 | 6.213 | 393.682 | 678.354 | 397.335 | 205.413 | 24.014 | 24.385 | 1.951 |
1970 | 0.070 | 0.000 | 0.001 | 16.218 | 68.036 | 300.546 | 330.502 | 283.476 | 158.640 | 115.758 | 0.260 | 0.000 |
1971 | 0.000 | 0.000 | 0.000 | 0.812 | 57.691 | 297.187 | 122.195 | 372.693 | 286.056 | 39.424 | 0.554 | 0.000 |
1972 | 0.000 | 0.029 | 0.000 | 5.982 | 19.101 | 132.413 | 338.484 | 68.741 | 120.415 | 1.078 | 24.089 | 0.143 |
1973 | 0.000 | 2.969 | 0.234 | 3.925 | 14.978 | 304.484 | 696.024 | 256.932 | 183.206 | 101.805 | 5.516 | 0.000 |
1974 | 0.000 | 0.000 | 6.427 | 16.864 | 51.209 | 148.697 | 405.359 | 319.651 | 288.533 | 188.876 | 0.260 | 0.000 |
1975 | 0.333 | 0.585 | 0.000 | 0.061 | 30.651 | 359.369 | 474.143 | 404.372 | 400.001 | 105.560 | 2.763 | 0.000 |
1976 | 0.000 | 0.000 | 5.993 | 4.454 | 3.577 | 773.737 | 545.379 | 436.912 | 108.459 | 13.611 | 44.887 | 4.158 |
1977 | 0.000 | 2.981 | 3.289 | 4.432 | 32.130 | 319.716 | 407.246 | 129.678 | 89.150 | 83.193 | 122.809 | 7.530 |
1978 | 0.061 | 4.197 | 4.004 | 44.623 | 52.950 | 403.860 | 192.399 | 239.066 | 139.119 | 26.711 | 60.996 | 0.597 |
1979 | 0.000 | 0.386 | 3.343 | 0.126 | 6.860 | 342.324 | 403.925 | 451.153 | 440.381 | 19.084 | 101.597 | 0.008 |
1980 | 0.008 | 0.000 | 8.329 | 28.764 | 4.816 | 349.975 | 344.268 | 404.191 | 94.127 | 10.826 | 15.533 | 7.348 |
1981 | 2.257 | 2.121 | 0.445 | 10.817 | 17.193 | 360.788 | 507.155 | 217.037 | 361.165 | 80.018 | 3.715 | 0.050 |
1982 | 0.000 | 0.560 | 0.000 | 14.585 | 50.468 | 145.343 | 186.691 | 194.307 | 239.402 | 49.257 | 62.474 | 0.000 |
1983 | 0.395 | 0.000 | 0.000 | 0.061 | 1.056 | 225.847 | 390.041 | 537.764 | 428.050 | 30.771 | 1.008 | 1.955 |
1984 | 0.000 | 0.391 | 5.772 | 4.997 | 0.508 | 367.058 | 621.607 | 138.006 | 229.276 | 167.164 | 3.786 | 0.396 |
1985 | 0.025 | 0.000 | 0.922 | 11.512 | 6.458 | 234.930 | 325.191 | 297.802 | 88.877 | 139.919 | 108.561 | 0.655 |
1986 | 0.000 | 1.229 | 0.000 | 4.567 | 22.547 | 635.977 | 202.570 | 247.395 | 105.095 | 3.746 | 7.457 | 37.386 |
1987 | 3.013 | 8.410 | 1.367 | 3.864 | 80.539 | 200.950 | 172.864 | 477.113 | 44.574 | 150.179 | 18.281 | 36.845 |
1988 | 0.000 | 0.000 | 0.000 | 43.570 | 12.862 | 186.431 | 740.613 | 211.781 | 613.522 | 12.375 | 0.458 | 1.037 |
1989 | 0.008 | 0.000 | 9.619 | 20.774 | 20.176 | 425.984 | 484.451 | 177.257 | 236.803 | 23.424 | 0.585 | 0.943 |
1990 | 0.004 | 0.531 | 0.789 | 0.274 | 78.384 | 423.314 | 583.557 | 451.707 | 69.182 | 115.349 | 41.888 | 1.315 |
1991 | 0.004 | 0.071 | 0.972 | 27.964 | 30.405 | 565.900 | 479.719 | 193.423 | 178.727 | 4.135 | 15.936 | 0.000 |
1992 | 0.000 | 0.000 | 0.000 | 3.165 | 9.580 | 227.180 | 321.551 | 428.764 | 287.582 | 40.079 | 5.982 | 0.000 |
1993 | 0.000 | 0.078 | 1.211 | 2.062 | 3.248 | 234.068 | 450.088 | 150.278 | 101.928 | 225.904 | 6.240 | 35.147 |
1994 | 0.879 | 0.325 | 2.415 | 16.823 | 33.378 | 749.030 | 707.986 | 230.898 | 115.509 | 116.348 | 14.098 | 0.000 |
1995 | 0.695 | 0.000 | 1.770 | 25.949 | 23.964 | 163.515 | 501.461 | 114.206 | 288.262 | 84.359 | 4.866 | 0.021 |
1996 | 0.016 | 2.779 | 0.087 | 6.318 | 5.134 | 453.607 | 558.586 | 212.489 | 203.642 | 176.471 | 12.202 | 0.000 |
1997 | 1.284 | 0.000 | 0.747 | 23.912 | 4.664 | 673.831 | 422.913 | 541.579 | 60.477 | 31.050 | 65.392 | 18.991 |
1998 | 0.008 | 2.671 | 0.073 | 0.377 | 15.717 | 238.609 | 590.663 | 362.357 | 243.444 | 96.324 | 52.965 | 0.035 |
1999 | 0.000 | 1.431 | 0.000 | 0.642 | 35.828 | 415.471 | 277.137 | 98.616 | 225.962 | 180.300 | 0.263 | 0.033 |
2000 | 0.000 | 0.170 | 0.000 | 1.193 | 26.237 | 371.328 | 265.417 | 220.814 | 147.196 | 38.246 | 15.274 | 8.187 |
2001 | 0.147 | 0.000 | 2.178 | 1.528 | 7.860 | 247.982 | 279.547 | 189.404 | 158.025 | 135.518 | 23.633 | 0.003 |
2002 | 0.231 | 0.911 | 0.388 | 53.266 | 18.430 | 509.145 | 84.936 | 257.205 | 78.269 | 21.486 | 0.614 | 0.000 |
fig, ax = plt.subplots(nrows=3, ncols=1, figsize=(12, 5), sharex=True, sharey=True)
ax[0].plot(df_lluvias.index, df_lluvias['Jan'], label='Precipitaciones de enero')
ax[1].plot(df_lluvias.index, df_lluvias['Feb'], label='Precipitaciones de febrero', color='C1')
ax[2].plot(df_lluvias.index, df_lluvias['Mar'], label='Precipitaciones de marzo', color='C2')
ax[0].set_title('Precipitaciones de los primeros tres meses del año')
ax[2].set_xlabel('Año')
ax[1].set_ylabel('Precipitación (mm.)')
ax[0].legend()
ax[1].legend()
ax[2].legend()
<matplotlib.legend.Legend at 0x7f8c247e2490>
# FacetGrid
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time", row="sex")
g.map(sns.scatterplot, "total_bill", "tip")
<seaborn.axisgrid.FacetGrid at 0x7f8c24aa7210>
g = sns.FacetGrid(tips, col="time", hue="sex")
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")
g.add_legend()
<seaborn.axisgrid.FacetGrid at 0x7f8c243d5f50>
import matplotlib as mpl
mpl.rcParams['axes.titleweight'] = 'bold'
mpl.rcParams['axes.titlelocation'] = 'left'
mpl.rcParams['axes.titlecolor'] = 'firebrick'
mpl.rcParams['axes.labelcolor'] = 'blue'
mpl.rcParams['axes.labelsize'] = '10'
mpl.rcParams['axes.labelweight'] = 'light'
mpl.rcParams['axes.linewidth'] = '1'
mpl.rcParams['grid.color'] = 'black'
mpl.rcParams['grid.linestyle'] = '-.'
mpl.rcParams['grid.linewidth'] = '2'
fig, ax = plt.subplots(figsize=(7, 4))
ax.scatter(df_lluvias['Aug'], df_lluvias['Sep'], c=df_lluvias.index)
ax.set_title('(Título rojo en negrita)')
ax.set_xlabel('(Etiqueta eje horiz.)')
ax.set_ylabel('(Etiqueta eje vert.)')
Text(0, 0.5, '(Etiqueta eje vert.)')
# Restaurar por defecto
mpl.rcParams.update(mpl.rcParamsDefault)
mpl.rcParams.keys()
KeysView(RcParams({'_internal.classic_mode': False, 'agg.path.chunksize': 0, 'animation.avconv_args': [], 'animation.avconv_path': 'avconv', 'animation.bitrate': -1, 'animation.codec': 'h264', 'animation.convert_args': [], 'animation.convert_path': 'convert', 'animation.embed_limit': 20.0, 'animation.ffmpeg_args': [], 'animation.ffmpeg_path': 'ffmpeg', 'animation.frame_format': 'png', 'animation.html': 'none', 'animation.html_args': [], 'animation.writer': 'ffmpeg', 'axes.autolimit_mode': 'data', 'axes.axisbelow': 'line', 'axes.edgecolor': 'black', 'axes.facecolor': 'white', 'axes.formatter.limits': [-5, 6], 'axes.formatter.min_exponent': 0, 'axes.formatter.offset_threshold': 4, 'axes.formatter.use_locale': False, 'axes.formatter.use_mathtext': False, 'axes.formatter.useoffset': True, 'axes.grid': False, 'axes.grid.axis': 'both', 'axes.grid.which': 'major', 'axes.labelcolor': 'black', 'axes.labelpad': 4.0, 'axes.labelsize': 'medium', 'axes.labelweight': 'normal', 'axes.linewidth': 0.8, 'axes.prop_cycle': cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']), 'axes.spines.bottom': True, 'axes.spines.left': True, 'axes.spines.right': True, 'axes.spines.top': True, 'axes.titlecolor': 'auto', 'axes.titlelocation': 'center', 'axes.titlepad': 6.0, 'axes.titlesize': 'large', 'axes.titleweight': 'normal', 'axes.unicode_minus': True, 'axes.xmargin': 0.05, 'axes.ymargin': 0.05, 'axes3d.grid': True, 'backend': 'module://ipykernel.pylab.backend_inline', 'backend_fallback': True, 'boxplot.bootstrap': None, 'boxplot.boxprops.color': 'black', 'boxplot.boxprops.linestyle': '-', 'boxplot.boxprops.linewidth': 1.0, 'boxplot.capprops.color': 'black', 'boxplot.capprops.linestyle': '-', 'boxplot.capprops.linewidth': 1.0, 'boxplot.flierprops.color': 'black', 'boxplot.flierprops.linestyle': 'none', 'boxplot.flierprops.linewidth': 1.0, 'boxplot.flierprops.marker': 'o', 'boxplot.flierprops.markeredgecolor': 'black', 'boxplot.flierprops.markeredgewidth': 1.0, 'boxplot.flierprops.markerfacecolor': 'none', 'boxplot.flierprops.markersize': 6.0, 'boxplot.meanline': False, 'boxplot.meanprops.color': 'C2', 'boxplot.meanprops.linestyle': '--', 'boxplot.meanprops.linewidth': 1.0, 'boxplot.meanprops.marker': '^', 'boxplot.meanprops.markeredgecolor': 'C2', 'boxplot.meanprops.markerfacecolor': 'C2', 'boxplot.meanprops.markersize': 6.0, 'boxplot.medianprops.color': 'C1', 'boxplot.medianprops.linestyle': '-', 'boxplot.medianprops.linewidth': 1.0, 'boxplot.notch': False, 'boxplot.patchartist': False, 'boxplot.showbox': True, 'boxplot.showcaps': True, 'boxplot.showfliers': True, 'boxplot.showmeans': False, 'boxplot.vertical': True, 'boxplot.whiskerprops.color': 'black', 'boxplot.whiskerprops.linestyle': '-', 'boxplot.whiskerprops.linewidth': 1.0, 'boxplot.whiskers': 1.5, 'contour.corner_mask': True, 'contour.negative_linestyle': 'dashed', 'datapath': '/usr/local/lib/python3.7/dist-packages/matplotlib/mpl-data', 'date.autoformatter.day': '%Y-%m-%d', 'date.autoformatter.hour': '%m-%d %H', 'date.autoformatter.microsecond': '%M:%S.%f', 'date.autoformatter.minute': '%d %H:%M', 'date.autoformatter.month': '%Y-%m', 'date.autoformatter.second': '%H:%M:%S', 'date.autoformatter.year': '%Y', 'docstring.hardcopy': False, 'errorbar.capsize': 0.0, 'figure.autolayout': False, 'figure.constrained_layout.h_pad': 0.04167, 'figure.constrained_layout.hspace': 0.02, 'figure.constrained_layout.use': False, 'figure.constrained_layout.w_pad': 0.04167, 'figure.constrained_layout.wspace': 0.02, 'figure.dpi': 100.0, 'figure.edgecolor': 'white', 'figure.facecolor': 'white', 'figure.figsize': [6.4, 4.8], 'figure.frameon': True, 'figure.max_open_warning': 20, 'figure.subplot.bottom': 0.11, 'figure.subplot.hspace': 0.2, 'figure.subplot.left': 0.125, 'figure.subplot.right': 0.9, 'figure.subplot.top': 0.88, 'figure.subplot.wspace': 0.2, 'figure.titlesize': 'large', 'figure.titleweight': 'normal', 'font.cursive': ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'cursive'], 'font.family': ['sans-serif'], 'font.fantasy': ['Comic Neue', 'Comic Sans MS', 'Chicago', 'Charcoal', 'Impact', 'Western', 'Humor Sans', 'xkcd', 'fantasy'], 'font.monospace': ['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace'], 'font.sans-serif': ['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'], 'font.serif': ['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'], 'font.size': 10.0, 'font.stretch': 'normal', 'font.style': 'normal', 'font.variant': 'normal', 'font.weight': 'normal', 'grid.alpha': 1.0, 'grid.color': '#b0b0b0', 'grid.linestyle': '-', 'grid.linewidth': 0.8, 'hatch.color': 'black', 'hatch.linewidth': 1.0, 'hist.bins': 10, 'image.aspect': 'equal', 'image.cmap': 'viridis', 'image.composite_image': True, 'image.interpolation': 'antialiased', 'image.lut': 256, 'image.origin': 'upper', 'image.resample': True, 'interactive': False, 'keymap.all_axes': ['a'], 'keymap.back': ['left', 'c', 'backspace', 'MouseButton.BACK'], 'keymap.copy': ['ctrl+c', 'cmd+c'], 'keymap.forward': ['right', 'v', 'MouseButton.FORWARD'], 'keymap.fullscreen': ['f', 'ctrl+f'], 'keymap.grid': ['g'], 'keymap.grid_minor': ['G'], 'keymap.help': ['f1'], 'keymap.home': ['h', 'r', 'home'], 'keymap.pan': ['p'], 'keymap.quit': ['ctrl+w', 'cmd+w', 'q'], 'keymap.quit_all': ['W', 'cmd+W', 'Q'], 'keymap.save': ['s', 'ctrl+s'], 'keymap.xscale': ['k', 'L'], 'keymap.yscale': ['l'], 'keymap.zoom': ['o'], 'legend.borderaxespad': 0.5, 'legend.borderpad': 0.4, 'legend.columnspacing': 2.0, 'legend.edgecolor': '0.8', 'legend.facecolor': 'inherit', 'legend.fancybox': True, 'legend.fontsize': 'medium', 'legend.framealpha': 0.8, 'legend.frameon': True, 'legend.handleheight': 0.7, 'legend.handlelength': 2.0, 'legend.handletextpad': 0.8, 'legend.labelspacing': 0.5, 'legend.loc': 'best', 'legend.markerscale': 1.0, 'legend.numpoints': 1, 'legend.scatterpoints': 1, 'legend.shadow': False, 'legend.title_fontsize': None, 'lines.antialiased': True, 'lines.color': 'C0', 'lines.dash_capstyle': 'butt', 'lines.dash_joinstyle': 'round', 'lines.dashdot_pattern': [6.4, 1.6, 1.0, 1.6], 'lines.dashed_pattern': [3.7, 1.6], 'lines.dotted_pattern': [1.0, 1.65], 'lines.linestyle': '-', 'lines.linewidth': 1.5, 'lines.marker': 'None', 'lines.markeredgecolor': 'auto', 'lines.markeredgewidth': 1.0, 'lines.markerfacecolor': 'auto', 'lines.markersize': 6.0, 'lines.scale_dashes': True, 'lines.solid_capstyle': 'projecting', 'lines.solid_joinstyle': 'round', 'markers.fillstyle': 'full', 'mathtext.bf': 'sans:bold', 'mathtext.cal': 'cursive', 'mathtext.default': 'it', 'mathtext.fallback_to_cm': True, 'mathtext.fontset': 'dejavusans', 'mathtext.it': 'sans:italic', 'mathtext.rm': 'sans', 'mathtext.sf': 'sans', 'mathtext.tt': 'monospace', 'mpl_toolkits.legacy_colorbar': True, 'patch.antialiased': True, 'patch.edgecolor': 'black', 'patch.facecolor': 'C0', 'patch.force_edgecolor': False, 'patch.linewidth': 1.0, 'path.effects': [], 'path.simplify': True, 'path.simplify_threshold': 0.1111111111111111, 'path.sketch': None, 'path.snap': True, 'pdf.compression': 6, 'pdf.fonttype': 3, 'pdf.inheritcolor': False, 'pdf.use14corefonts': False, 'pgf.preamble': '', 'pgf.rcfonts': True, 'pgf.texsystem': 'xelatex', 'polaraxes.grid': True, 'ps.distiller.res': 6000, 'ps.fonttype': 3, 'ps.papersize': 'letter', 'ps.useafm': False, 'ps.usedistiller': None, 'savefig.bbox': None, 'savefig.directory': '~', 'savefig.dpi': 'figure', 'savefig.edgecolor': 'white', 'savefig.facecolor': 'white', 'savefig.format': 'png', 'savefig.frameon': True, 'savefig.jpeg_quality': 95, 'savefig.orientation': 'portrait', 'savefig.pad_inches': 0.1, 'savefig.transparent': False, 'scatter.edgecolors': 'face', 'scatter.marker': 'o', 'svg.fonttype': 'path', 'svg.hashsalt': None, 'svg.image_inline': True, 'text.antialiased': True, 'text.color': 'black', 'text.hinting': 'auto', 'text.hinting_factor': 8, 'text.kerning_factor': 0, 'text.latex.preamble': '', 'text.latex.preview': False, 'text.latex.unicode': True, 'text.usetex': False, 'timezone': 'UTC', 'tk.window_focus': False, 'toolbar': 'toolbar2', 'verbose.fileo': 'sys.stdout', 'verbose.level': 'silent', 'webagg.address': '127.0.0.1', 'webagg.open_in_browser': True, 'webagg.port': 8988, 'webagg.port_retries': 50, 'xtick.alignment': 'center', 'xtick.bottom': True, 'xtick.color': 'black', 'xtick.direction': 'out', 'xtick.labelbottom': True, 'xtick.labelsize': 'medium', 'xtick.labeltop': False, 'xtick.major.bottom': True, 'xtick.major.pad': 3.5, 'xtick.major.size': 3.5, 'xtick.major.top': True, 'xtick.major.width': 0.8, 'xtick.minor.bottom': True, 'xtick.minor.pad': 3.4, 'xtick.minor.size': 2.0, 'xtick.minor.top': True, 'xtick.minor.visible': False, 'xtick.minor.width': 0.6, 'xtick.top': False, 'ytick.alignment': 'center_baseline', 'ytick.color': 'black', 'ytick.direction': 'out', 'ytick.labelleft': True, 'ytick.labelright': False, 'ytick.labelsize': 'medium', 'ytick.left': True, 'ytick.major.left': True, 'ytick.major.pad': 3.5, 'ytick.major.right': True, 'ytick.major.size': 3.5, 'ytick.major.width': 0.8, 'ytick.minor.left': True, 'ytick.minor.pad': 3.4, 'ytick.minor.right': True, 'ytick.minor.size': 2.0, 'ytick.minor.visible': False, 'ytick.minor.width': 0.6, 'ytick.right': False}))
mpl.rcParams
RcParams({'_internal.classic_mode': False, 'agg.path.chunksize': 0, 'animation.avconv_args': [], 'animation.avconv_path': 'avconv', 'animation.bitrate': -1, 'animation.codec': 'h264', 'animation.convert_args': [], 'animation.convert_path': 'convert', 'animation.embed_limit': 20.0, 'animation.ffmpeg_args': [], 'animation.ffmpeg_path': 'ffmpeg', 'animation.frame_format': 'png', 'animation.html': 'none', 'animation.html_args': [], 'animation.writer': 'ffmpeg', 'axes.autolimit_mode': 'data', 'axes.axisbelow': True, 'axes.edgecolor': 'white', 'axes.facecolor': '#EAEAF2', 'axes.formatter.limits': [-5, 6], 'axes.formatter.min_exponent': 0, 'axes.formatter.offset_threshold': 4, 'axes.formatter.use_locale': False, 'axes.formatter.use_mathtext': False, 'axes.formatter.useoffset': True, 'axes.grid': True, 'axes.grid.axis': 'both', 'axes.grid.which': 'major', 'axes.labelcolor': 'red', 'axes.labelpad': 4.0, 'axes.labelsize': 'medium', 'axes.labelweight': 'normal', 'axes.linewidth': 0.8, 'axes.prop_cycle': cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']), 'axes.spines.bottom': True, 'axes.spines.left': True, 'axes.spines.right': True, 'axes.spines.top': True, 'axes.titlecolor': 'auto', 'axes.titlelocation': 'center', 'axes.titlepad': 6.0, 'axes.titlesize': 'large', 'axes.titleweight': 'normal', 'axes.unicode_minus': True, 'axes.xmargin': 0.05, 'axes.ymargin': 0.05, 'axes3d.grid': True, 'backend': 'module://ipykernel.pylab.backend_inline', 'backend_fallback': True, 'boxplot.bootstrap': None, 'boxplot.boxprops.color': 'black', 'boxplot.boxprops.linestyle': '-', 'boxplot.boxprops.linewidth': 1.0, 'boxplot.capprops.color': 'black', 'boxplot.capprops.linestyle': '-', 'boxplot.capprops.linewidth': 1.0, 'boxplot.flierprops.color': 'black', 'boxplot.flierprops.linestyle': 'none', 'boxplot.flierprops.linewidth': 1.0, 'boxplot.flierprops.marker': 'o', 'boxplot.flierprops.markeredgecolor': 'black', 'boxplot.flierprops.markeredgewidth': 1.0, 'boxplot.flierprops.markerfacecolor': 'none', 'boxplot.flierprops.markersize': 6.0, 'boxplot.meanline': False, 'boxplot.meanprops.color': 'C2', 'boxplot.meanprops.linestyle': '--', 'boxplot.meanprops.linewidth': 1.0, 'boxplot.meanprops.marker': '^', 'boxplot.meanprops.markeredgecolor': 'C2', 'boxplot.meanprops.markerfacecolor': 'C2', 'boxplot.meanprops.markersize': 6.0, 'boxplot.medianprops.color': 'C1', 'boxplot.medianprops.linestyle': '-', 'boxplot.medianprops.linewidth': 1.0, 'boxplot.notch': False, 'boxplot.patchartist': False, 'boxplot.showbox': True, 'boxplot.showcaps': True, 'boxplot.showfliers': True, 'boxplot.showmeans': False, 'boxplot.vertical': True, 'boxplot.whiskerprops.color': 'black', 'boxplot.whiskerprops.linestyle': '-', 'boxplot.whiskerprops.linewidth': 1.0, 'boxplot.whiskers': 1.5, 'contour.corner_mask': True, 'contour.negative_linestyle': 'dashed', 'datapath': '/usr/local/lib/python3.7/dist-packages/matplotlib/mpl-data', 'date.autoformatter.day': '%Y-%m-%d', 'date.autoformatter.hour': '%m-%d %H', 'date.autoformatter.microsecond': '%M:%S.%f', 'date.autoformatter.minute': '%d %H:%M', 'date.autoformatter.month': '%Y-%m', 'date.autoformatter.second': '%H:%M:%S', 'date.autoformatter.year': '%Y', 'docstring.hardcopy': False, 'errorbar.capsize': 0.0, 'figure.autolayout': False, 'figure.constrained_layout.h_pad': 0.04167, 'figure.constrained_layout.hspace': 0.02, 'figure.constrained_layout.use': False, 'figure.constrained_layout.w_pad': 0.04167, 'figure.constrained_layout.wspace': 0.02, 'figure.dpi': 100.0, 'figure.edgecolor': 'white', 'figure.facecolor': 'white', 'figure.figsize': [6.4, 4.8], 'figure.frameon': True, 'figure.max_open_warning': 20, 'figure.subplot.bottom': 0.11, 'figure.subplot.hspace': 0.2, 'figure.subplot.left': 0.125, 'figure.subplot.right': 0.9, 'figure.subplot.top': 0.88, 'figure.subplot.wspace': 0.2, 'figure.titlesize': 'large', 'figure.titleweight': 'normal', 'font.cursive': ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'cursive'], 'font.family': ['sans-serif'], 'font.fantasy': ['Comic Neue', 'Comic Sans MS', 'Chicago', 'Charcoal', 'Impact', 'Western', 'Humor Sans', 'xkcd', 'fantasy'], 'font.monospace': ['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace'], 'font.sans-serif': ['Arial', 'DejaVu Sans', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif'], 'font.serif': ['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'], 'font.size': 10.0, 'font.stretch': 'normal', 'font.style': 'normal', 'font.variant': 'normal', 'font.weight': 'normal', 'grid.alpha': 1.0, 'grid.color': 'purple', 'grid.linestyle': '--', 'grid.linewidth': 0.8, 'hatch.color': 'black', 'hatch.linewidth': 1.0, 'hist.bins': 10, 'image.aspect': 'equal', 'image.cmap': 'rocket', 'image.composite_image': True, 'image.interpolation': 'antialiased', 'image.lut': 256, 'image.origin': 'upper', 'image.resample': True, 'interactive': False, 'keymap.all_axes': ['a'], 'keymap.back': ['left', 'c', 'backspace', 'MouseButton.BACK'], 'keymap.copy': ['ctrl+c', 'cmd+c'], 'keymap.forward': ['right', 'v', 'MouseButton.FORWARD'], 'keymap.fullscreen': ['f', 'ctrl+f'], 'keymap.grid': ['g'], 'keymap.grid_minor': ['G'], 'keymap.help': ['f1'], 'keymap.home': ['h', 'r', 'home'], 'keymap.pan': ['p'], 'keymap.quit': ['ctrl+w', 'cmd+w', 'q'], 'keymap.quit_all': ['W', 'cmd+W', 'Q'], 'keymap.save': ['s', 'ctrl+s'], 'keymap.xscale': ['k', 'L'], 'keymap.yscale': ['l'], 'keymap.zoom': ['o'], 'legend.borderaxespad': 0.5, 'legend.borderpad': 0.4, 'legend.columnspacing': 2.0, 'legend.edgecolor': '0.8', 'legend.facecolor': 'inherit', 'legend.fancybox': True, 'legend.fontsize': 'medium', 'legend.framealpha': 0.8, 'legend.frameon': True, 'legend.handleheight': 0.7, 'legend.handlelength': 2.0, 'legend.handletextpad': 0.8, 'legend.labelspacing': 0.5, 'legend.loc': 'best', 'legend.markerscale': 1.0, 'legend.numpoints': 1, 'legend.scatterpoints': 1, 'legend.shadow': False, 'legend.title_fontsize': None, 'lines.antialiased': True, 'lines.color': 'C0', 'lines.dash_capstyle': 'butt', 'lines.dash_joinstyle': 'round', 'lines.dashdot_pattern': [6.4, 1.6, 1.0, 1.6], 'lines.dashed_pattern': [3.7, 1.6], 'lines.dotted_pattern': [1.0, 1.65], 'lines.linestyle': '-', 'lines.linewidth': 1.5, 'lines.marker': 'None', 'lines.markeredgecolor': 'auto', 'lines.markeredgewidth': 1.0, 'lines.markerfacecolor': 'auto', 'lines.markersize': 6.0, 'lines.scale_dashes': True, 'lines.solid_capstyle': 'round', 'lines.solid_joinstyle': 'round', 'markers.fillstyle': 'full', 'mathtext.bf': 'sans:bold', 'mathtext.cal': 'cursive', 'mathtext.default': 'it', 'mathtext.fallback_to_cm': True, 'mathtext.fontset': 'dejavusans', 'mathtext.it': 'sans:italic', 'mathtext.rm': 'sans', 'mathtext.sf': 'sans', 'mathtext.tt': 'monospace', 'mpl_toolkits.legacy_colorbar': True, 'patch.antialiased': True, 'patch.edgecolor': 'w', 'patch.facecolor': 'C0', 'patch.force_edgecolor': True, 'patch.linewidth': 1.0, 'path.effects': [], 'path.simplify': True, 'path.simplify_threshold': 0.1111111111111111, 'path.sketch': None, 'path.snap': True, 'pdf.compression': 6, 'pdf.fonttype': 3, 'pdf.inheritcolor': False, 'pdf.use14corefonts': False, 'pgf.preamble': '', 'pgf.rcfonts': True, 'pgf.texsystem': 'xelatex', 'polaraxes.grid': True, 'ps.distiller.res': 6000, 'ps.fonttype': 3, 'ps.papersize': 'letter', 'ps.useafm': False, 'ps.usedistiller': None, 'savefig.bbox': None, 'savefig.directory': '~', 'savefig.dpi': 'figure', 'savefig.edgecolor': 'white', 'savefig.facecolor': 'white', 'savefig.format': 'png', 'savefig.frameon': True, 'savefig.jpeg_quality': 95, 'savefig.orientation': 'portrait', 'savefig.pad_inches': 0.1, 'savefig.transparent': False, 'scatter.edgecolors': 'face', 'scatter.marker': 'o', 'svg.fonttype': 'path', 'svg.hashsalt': None, 'svg.image_inline': True, 'text.antialiased': True, 'text.color': '.15', 'text.hinting': 'auto', 'text.hinting_factor': 8, 'text.kerning_factor': 0, 'text.latex.preamble': '', 'text.latex.preview': False, 'text.latex.unicode': True, 'text.usetex': False, 'timezone': 'UTC', 'tk.window_focus': False, 'toolbar': 'toolbar2', 'verbose.fileo': 'sys.stdout', 'verbose.level': 'silent', 'webagg.address': '127.0.0.1', 'webagg.open_in_browser': True, 'webagg.port': 8988, 'webagg.port_retries': 50, 'xtick.alignment': 'center', 'xtick.bottom': False, 'xtick.color': '.15', 'xtick.direction': 'out', 'xtick.labelbottom': True, 'xtick.labelsize': 'medium', 'xtick.labeltop': False, 'xtick.major.bottom': True, 'xtick.major.pad': 3.5, 'xtick.major.size': 3.5, 'xtick.major.top': True, 'xtick.major.width': 0.8, 'xtick.minor.bottom': True, 'xtick.minor.pad': 3.4, 'xtick.minor.size': 2.0, 'xtick.minor.top': True, 'xtick.minor.visible': False, 'xtick.minor.width': 0.6, 'xtick.top': False, 'ytick.alignment': 'center_baseline', 'ytick.color': '.15', 'ytick.direction': 'out', 'ytick.labelleft': True, 'ytick.labelright': False, 'ytick.labelsize': 'medium', 'ytick.left': False, 'ytick.major.left': True, 'ytick.major.pad': 3.5, 'ytick.major.right': True, 'ytick.major.size': 3.5, 'ytick.major.width': 0.8, 'ytick.minor.left': True, 'ytick.minor.pad': 3.4, 'ytick.minor.right': True, 'ytick.minor.size': 2.0, 'ytick.minor.visible': False, 'ytick.minor.width': 0.6, 'ytick.right': False})
sns.set_style(style="darkgrid", rc={"grid.color": ".6"})
sns.set_style(rc={"grid.linestyle": ":"})
sns.set_style(rc={"axes.titleweight": "normal"})
sns.set_style(rc={"axes.titlelocation": "left"})
sns.set_style(rc={"axes.titlecolor": "blue"})
sns.set_style(rc={"axes.labelcolor": "red"})
sns.set_style(rc={"axes.labelsize": "12"})
sns.set_style(rc={"axes.labelweight": "normal"})
sns.set_style(rc={"axes.linewidth": "0.5"})
sns.set_style(rc={"grid.color": "purple"})
sns.set_style(rc={"grid.linestyle": "--"})
sns.set_style(rc={"grid.linewidth": "0.5"})
sns.set_style(rc={"font.fantasy": "Comic Sans MS"})
sns.set_style(rc={"font.serif": "Utopia"})
penguins = sns.load_dataset("penguins")
# Axis-level
sns.histplot(data=penguins, x="flipper_length_mm")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c22ea6f90>
sns.reset_orig()
penguins = sns.load_dataset("penguins")
# Axis-level
sns.histplot(data=penguins, x="flipper_length_mm")
<matplotlib.axes._subplots.AxesSubplot at 0x7f8c22e3bc10>
# Ejemplo aplicado
df_ejercicio = sns.load_dataset('exercise')
df_ejercicio = df_ejercicio.drop('Unnamed: 0', axis='columns')
df_ejercicio.head()
id | diet | pulse | time | kind | |
---|---|---|---|---|---|
0 | 1 | low fat | 85 | 1 min | rest |
1 | 1 | low fat | 85 | 15 min | rest |
2 | 1 | low fat | 88 | 30 min | rest |
3 | 2 | low fat | 90 | 1 min | rest |
4 | 2 | low fat | 92 | 15 min | rest |
df_30_min = df_ejercicio[df_ejercicio['time'] == '30 min']
df_30_min.head()
id | diet | pulse | time | kind | |
---|---|---|---|---|---|
2 | 1 | low fat | 88 | 30 min | rest |
5 | 2 | low fat | 93 | 30 min | rest |
8 | 3 | low fat | 94 | 30 min | rest |
11 | 4 | low fat | 83 | 30 min | rest |
14 | 5 | low fat | 91 | 30 min | rest |
plt.figure()
# Figure -level
ax = sns.displot(data=df_30_min, x='pulse', kind='kde', hue='kind', fill=True)
ax.set(xlabel='Frecuencia Cardíaca', ylabel='Densidad', title='Distribución de las pulsaciones')
<seaborn.axisgrid.FacetGrid at 0x7f8c22d2fd10>
<Figure size 432x288 with 0 Axes>
ax = sns.catplot(data=df_ejercicio, kind='violin', x='time', y='pulse', hue='diet', split=True)
ax.set(xlabel='Duración de ejercicio', ylabel='Frecuencia cardíaca', title='Categorización de la distribución de pulsaciones')
<seaborn.axisgrid.FacetGrid at 0x7f8c22cdb410>