Usen este mega hack para poder ver todos los estilos aplicados
for i in plt.style.available:
plt.style.use(i)
fig, ax = plt.subplots(figsize=(5,5))
ax.plot(x, y)
y ya me lo agradecerán
Visualización de datos con Python
La importancia de la visualización de datos
Matplotlib
Pyplot básico
Subplot
Método orientado a objetos
Subplots
Leyendas, etiquetas, tÃtulos, tamaño
Colores y estilos
Bar Plot
Crear otro tipo de gráficas
Quiz: Matplotlib
Seaborn
Seaborn
Set
Parámetros más usados con Seaborn
Distribuciones
Categóricos
Relation
Jointplot y Pairplot
Heatmap
Quiz: Seaborn
Cierre del curso
Posibilidades con Matplotlib y Seaborn
Aún no tienes acceso a esta clase
Crea una cuenta y continúa viendo este curso
Aportes 7
Preguntas 1
Usen este mega hack para poder ver todos los estilos aplicados
for i in plt.style.available:
plt.style.use(i)
fig, ax = plt.subplots(figsize=(5,5))
ax.plot(x, y)
y ya me lo agradecerán
Hola a todos, aquà les dejo una imagen con las distintas configuraciones de estilo (style cheatsheet) y que pueden guardar para futura referencia.
Sprint
Link del colab: https://colab.research.google.com/drive/1GGwoG8O33nI9v__WeiBhO3B4h1b6Vf-M?usp=sharing
Pueden usar este código para poder visualizar los colores de forma mas bonita 😃.
# Lista de colores
import matplotlib.colors as mcolors
import matplotlib.patches as mpatch
overlap = {name for name in mcolors.CSS4_COLORS
if f'xkcd:{name}' in mcolors.XKCD_COLORS}
fig = plt.figure(figsize=[9, 5])
ax = fig.add_axes([0, 0, 1, 1])
n_groups = 3
n_rows = len(overlap) // n_groups + 1
for j, color_name in enumerate(sorted(overlap)):
css4 = mcolors.CSS4_COLORS[color_name]
xkcd = mcolors.XKCD_COLORS[f'xkcd:{color_name}'].upper()
# Pick text colour based on perceived luminance.
rgba = mcolors.to_rgba_array([css4, xkcd])
luma = 0.299 * rgba[:, 0] + 0.587 * rgba[:, 1] + 0.114 * rgba[:, 2]
css4_text_color = 'k' if luma[0] > 0.5 else 'w'
xkcd_text_color = 'k' if luma[1] > 0.5 else 'w'
col_shift = (j // n_rows) * 3
y_pos = j % n_rows
text_args = dict(fontsize=10, weight='bold' if css4 == xkcd else None)
ax.add_patch(mpatch.Rectangle((0 + col_shift, y_pos), 1, 1, color=css4))
ax.add_patch(mpatch.Rectangle((1 + col_shift, y_pos), 1, 1, color=xkcd))
ax.text(0.5 + col_shift, y_pos + .7, css4,
color=css4_text_color, ha='center', **text_args)
ax.text(1.5 + col_shift, y_pos + .7, xkcd,
color=xkcd_text_color, ha='center', **text_args)
ax.text(2 + col_shift, y_pos + .7, f' {color_name}', **text_args)
for g in range(n_groups):
ax.hlines(range(n_rows), 3*g, 3*g + 2.8, color='0.7', linewidth=1)
ax.text(0.5 + 3*g, -0.3, 'X11/CSS4', ha='center')
ax.text(1.5 + 3*g, -0.3, 'xkcd', ha='center')
ax.set_xlim(0, 3 * n_groups)
ax.set_ylim(n_rows, -1)
ax.axis('off')
plt.show()
Estuve investigando un poco más sobre los estilos y noté que literalmente se puede personalizar todo.
fig, ax = plt.subplots(figsize = (6,6), facecolor= (.18, .31, .31)) # Parte externa
ax.set_facecolor('#eafff5') # Parte interna
ax.set_title('LINE', color= 'peachpuff')
ax.set_xlabel('x', color = 'c')
ax.set_ylabel('y', color = 'c')
ax.tick_params(labelcolor='orange') #Parámetros del gráfico
ax.plot(x,x,color = '#D426C8', alpha= 0.5, linewidth= 18)
ax.grid(True) #grilla
👾🚀
La verdad es que Matplotlib es poderosÃsimo. Paso gráficos usando distintos estilos que encontré en la página de MATPLOTLIB
FUENTE 1: https://matplotlib.org/3.1.0/gallery/style_sheets/dark_background.html
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('dark_background')
fig, ax = plt.subplots()
L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.prop_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
ax.plot(x, np.sin(x + s), 'o-')
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_title("'dark_background' style sheet")
plt.show()
FUENTE 2: https://matplotlib.org/3.5.0/users/prev_whats_new/dflt_style_changes.html
import matplotlib.pyplot as plt
import numpy as np
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
fig.subplots_adjust(wspace=0.3)
th = np.linspace(0, 2*np.pi, 128)
N = 5
def demo(ax, extra_kwargs, title):
ax.set_title(title)
return [ax.fill_between(th, np.sin((j / N) * np.pi + th), alpha=.5, **extra_kwargs)
for j in range(N)]
demo(ax1, {'facecolor': 'C0'}, 'classic')
demo(ax2, {}, 'v2.0')
FUENTE 3: https://matplotlib.org/matplotblog/posts/matplotlib-cyberpunk-style/
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use("dark_background")
for param in ['text.color', 'axes.labelcolor', 'xtick.color', 'ytick.color']:
plt.rcParams[param] = '0.9' # very light grey
for param in ['figure.facecolor', 'axes.facecolor', 'savefig.facecolor']:
plt.rcParams[param] = '#212946' # bluish dark grey
colors = [
'#08F7FE', # teal/cyan
'#FE53BB', # pink
'#F5D300', # yellow
'#00ff41', # matrix green
]
df = pd.DataFrame({'A': [1, 3, 9, 5, 2, 1, 1],
'B': [4, 5, 5, 7, 9, 8, 6]})
fig, ax = plt.subplots()
df.plot(marker='o', color=colors, ax=ax)
# Redraw the data with low alpha and slighty increased linewidth:
n_shades = 10
diff_linewidth = 1.05
alpha_value = 0.3 / n_shades
for n in range(1, n_shades+1):
df.plot(marker='o',
linewidth=2+(diff_linewidth*n),
alpha=alpha_value,
legend=False,
ax=ax,
color=colors)
# Color the areas below the lines:
for column, color in zip(df, colors):
ax.fill_between(x=df.index,
y1=df[column].values,
y2=[0] * len(df),
color=color,
alpha=0.1)
ax.grid(color='#2A3459')
ax.set_xlim([ax.get_xlim()[0] - 0.2, ax.get_xlim()[1] + 0.2]) # to not have the markers cut off
ax.set_ylim(0)
plt.show()
Con este hack podrán ver todos los estilos aplicados y sus respectivos nombres arriba de cada gráfico.
for i in plt.style.available:
plt.style.use(i)
print(i)
fig, ax = plt.subplots(figsize=(5,5))
ax.plot(x)
plt.show()
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.