Skip to content Skip to sidebar Skip to footer

Matplotlib How To Change Figsize For Matshow

How to change figsize for matshow() in jupyter notebook? For example this code change figure size %matplotlib inline import matplotlib.pyplot as plt import pandas as pd d = pd.Dat

Solution 1:

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())
    

Solution 2:

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')

Solution 3:

Improving on the solution by @ImportanceOfBeingErnest,

matfig = plt.figure(figsize=(8,8))
plt.matshow(d.corr(), fignum=matfig.number)

This way you don't need to keep track of figure numbers.


Post a Comment for "Matplotlib How To Change Figsize For Matshow"