Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib如何更改matshow的figsize_Python_Pandas_Matplotlib - Fatal编程技术网

Python Matplotlib如何更改matshow的figsize

Python Matplotlib如何更改matshow的figsize,python,pandas,matplotlib,Python,Pandas,Matplotlib,如何更改jupyter笔记本中的figsize 例如,此代码更改图形大小 %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) 但下面

如何更改jupyter笔记本中的figsize

例如,此代码更改图形大小

%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)
但下面的代码不起作用

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

默认情况下,
plt.matshow()
生成自己的地物,因此结合
plt.figure()
将创建两个地物,主持matshow绘图的地物不是具有figsize集的地物

有两种选择:

  • 使用
    fignum
    参数

    plt.figure(figsize=(10,5))
    plt.matshow(d.corr(), fignum=1)
    
  • 使用
    matplotlib.axes.axes.matshow而不是
    pyplot.matshow
    绘制matshow

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

  • 通过@ImportanceOfBeingErnest改进解决方案

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

    这样,您就不需要跟踪数字了。

    解决方案对我不起作用,但我找到了另一种方法:

    plt.图(figsize=(10,5))
    plt.matshow(d.corr(),fignum=1,aspect='auto')
    
    太棒了!plt.figure(figsize=(10,5))plt.matshow(d.corr(),fignum=1)