Matplotlib how to change figsize for matshow

How to change figsize for matshow () in jupyter laptop?

For example, this code resize size

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

But the code below does not work

 %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()) 
+14
source share
3 answers

By default, plt.matshow() creates its own shape, so in combination with plt.figure() two numbers will be created, and the one that places the matshow graph is not the one that has a set of figists.

There are two options:

  • Use the fignum argument

     plt.figure(figsize=(10,5)) plt.matshow(d.corr(), fignum=1) 
  • Separate matshow with matplotlib.axes.Axes.matshow instead of pyplot.matshow .

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

Improving the solution with @ImportanceOfBeingErnest,

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

Thus, you do not need to keep track of figure numbers.

+1
source

The solutions did not help me, but I found another way:

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

Source: https://habr.com/ru/post/1265908/


All Articles