¿Cómo cambiar figsize para matshow () en el cuaderno jupyter?
Por ejemplo, este código cambia el tamaño de la figura.
%matplotlib inline import matplotlib.pyplot as plt import pandas as pd d = pd.DataFrame({'one' : [1, 2, 3, 4, 5], 'two' : [4, 3, 2, 1, 5]}) plt.figure(figsize=(10,5)) plt.plot(d.one, d.two)Pero el código de abajo no funciona
%matplotlib inline import matplotlib.pyplot as plt import pandas as pd d = pd.DataFrame({'one' : [1, 2, 3, 4, 5], 'two' : [4, 3, 2, 1, 5]}) plt.figure(figsize=(10,5)) plt.matshow(d.corr())De forma predeterminada, plt.matshow() produce su propia figura, por lo que, en combinación con plt.figure() , se crearán dos figuras y la que alberga el diagrama matshow no es la que tiene el conjunto figsize.
Hay dos opciones:
Usa el argumento fignum
plt.figure(figsize=(10,5)) plt.matshow(d.corr(), fignum=1) Trace el matshow usando matplotlib.axes.Axes.matshow en lugar de pyplot.matshow .
fig, ax = plt.subplots(figsize=(10,5)) ax.matshow(d.corr())Las soluciones no me funcionaron pero encontré otra forma:
plt.figure(figsize=(10,5)) plt.matshow(d.corr(), fignum=1, aspect='auto')Mejorando la solución de @ImportanceOfBeingErnest,
matfig = plt.figure(figsize=(8,8)) plt.matshow(d.corr(), fignum=matfig.number)De esta manera, no necesita realizar un seguimiento de los números de figura.