Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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 如何使用gridspec调整列宽?_Python_Matplotlib - Fatal编程技术网

Python 如何使用gridspec调整列宽?

Python 如何使用gridspec调整列宽?,python,matplotlib,Python,Matplotlib,我怎样才能修正这个情节 我想: 两个颜色栏不重叠 使其高度与绘图相等 这是我的密码: combined = (...) # some irrelevant to question data praparation - this variable contain square matrix with RGBA chanels plt.figure(dpi=300, figsize=(2.1,1.9)) gs = gridspec.GridSpec(1, 3, width_ratios=[20,1

我怎样才能修正这个情节

我想:

  • 两个颜色栏不重叠
  • 使其高度与绘图相等
  • 这是我的密码:

    combined = (...) # some irrelevant to question data praparation - this variable contain square matrix with RGBA chanels
    
    plt.figure(dpi=300, figsize=(2.1,1.9))
    gs = gridspec.GridSpec(1, 3, width_ratios=[20,1,1])
    ax1 = plt.subplot(gs[0])
    ax2 = plt.subplot(gs[1])
    ax3 = plt.subplot(gs[2])
    
    cax = ax1.imshow(combined, interpolation="None")
    mpl.colorbar.ColorbarBase(ax2, cmap=cmap_top, norm=norm_top)
    mpl.colorbar.ColorbarBase(ax3, cmap=cmap_top, norm=norm_top)
    
    我正在使用Python3.6和matplotlib 2.0


    在这种情况下,建议不要使用gridspec。您可以使用
    mpl\u工具箱中的
    make\u axes\u locatable
    类创建新的颜色条轴。axes\u grid1

    然后,您需要为分隔符的填充以及图形边距(使用
    子图\u adjust
    )找到一些合适的参数


    制作足够的空间,使色标标签不重叠,在这种情况下,几乎是图形宽度的一半,但我想这就是你想要的。

    < P>我会考虑1个问题的两种可能性: A.修改wspace参数,该参数控制图形之间的水平间距,即:

    gs = gridspec.GridSpec(1, 3, width_ratios=[20,1,1])
    gs.update(wspace=0.05)
    
    b。在第一个和第二个颜色栏之间添加一个额外的列,用作一些空白空间:

    gs = gridspec.GridSpec(1, 4, width_ratios=[20,1,0.15,1])
    
    (这里0.15只是一个例子)

    至于第二道题,我会用不同的方式来写(考虑到它对我来说相当有效:

    ax2=plt.subplot(gs[0,1]  )
    cb1 = matplotlib.colorbar.ColorbarBase(ax2, cmap="RdBu_r")
    
    希望有帮助

    ax2=plt.subplot(gs[0,1]  )
    cb1 = matplotlib.colorbar.ColorbarBase(ax2, cmap="RdBu_r")