2017-12-31 156 views
1

私は与えられた軸上に矩形の描画をプロットする関数(plot_fualt_axis()参照)を持っています。私はそのような軸をFigureにプロットし、Figureにカラーバーを追加しようとしています。カラーバーを追加しようとすると、隣接する軸のサイズが変更されていて、その周りには何も見つかりませんでした。matplotlibカラーバーの軸のサイズを変更

私のコード私はこのfigureを得ることから

from inversion_utilities import * 
import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.axes_grid1 import make_axes_locatable 


inv = build_inversion('resample_test/resample_test') 
grad_solutions = np.load('results/noise_test/grad_1000.npy') 
grad_std = np.std(grad_solutions, 0) 
cn_solutions = np.load('results/noise_test/resample_1000.npy') 
cn_std = np.std(cn_solutions, 0) 
uniform_solutions = np.load('results/noise_test/uniform_1000.npy') 
uniform_std = np.std(uniform_solutions, 0) 
f, axarr = plt.subplots(3, figsize=(15, 10)) 
plot_fualt_axis(inv.plains, axarr[0], uniform_std, False) 
plot_fualt_axis(inv.plains, axarr[1], grad_std, False) 
plot_fualt_axis(inv.plains, axarr[2], cn_std, False) 
divider = make_axes_locatable(axarr[2]) 
cax = divider.append_axes("bottom", size="10%", pad=0.3) 
norm = matplotlib.colors.Normalize(0, 0.001) 
my_cmap = cm.get_cmap('jet') 
cmmapable = cm.ScalarMappable(norm, my_cmap) 
cmmapable.set_array(np.linspace(0, 0.001)) 
colorbar(cmmapable, orientation='horizontal', cax=cax) 
plt.show() 

どこ上位2つの軸の両方bottem 1より大きい。 どうすればそれらのサイズを同じにすることができますか?

答えて

1

私はmake_axes_locatableに精通していませんでしたが、ドキュメントからは、axarr[2]を分割してカラーバーのスペースを確保しているようです。図にカラーバーの軸を直接追加することができます。もちろん、私はあなたのプロットを再現するが、ここで等高線図を使用した例であることはできません。

import matplotlib.pyplot as plt 
import numpy as np 

# Create some fake data and define levels for a contour plot. 
a = np.arange(12)[:,np.newaxis] * np.ones(8) 
levels = np.arange(1.5, 10, 2) 

# Create figure and axes array. 
f, axarr = plt.subplots(3, figsize=(15, 10)) 

# Make three identical contour plots. 
for i in range(3): 
    plt.sca(axarr[i]) 
    myplot = plt.contourf(a, cmap='RdYlBu', levels=levels, extend='both') 

# Find position of last contour plot and use this to set position of new 
# colorbar axes.  
left, bottom, width, height = axarr[2].get_position().bounds 
cax = f.add_axes([left, 0.03, width, height * 0.1]) 
plt.colorbar(myplot, orientation='horizontal', cax=cax) 

enter image description here

+0

のthnxは私のためによく働い –

関連する問題