Matplotlib how to change figsize for matshow

By default, plt.matshow() produces its own figure, so in combination with plt.figure() two figures will be created and the one that hosts the matshow plot is not the one that has the figsize set.

There are two options:

  1. Use the fignum argument

    plt.figure(figsize=(10,5))
    plt.matshow(d.corr(), fignum=1)
    
  2. Plot the matshow using matplotlib.axes.Axes.matshow instead of pyplot.matshow.

    fig, ax = plt.subplots(figsize=(10,5))
    ax.matshow(d.corr())
    

The solutions did not work for me but I found another way:

plt.figure(figsize=(10,5))
plt.matshow(d.corr(), fignum=1, aspect='auto')