2016-08-11 14 views
1

x軸を共有する2つのサブプロットがあります。第1のものはデータとフィット関数を有し、第2のものはデータとフィット関数との間の差である。図では、両方のサブプロットが同じy軸サイズ(ピクセル単位)を持っています。今私は、データのy軸とフィットのエラーの軸よりも大きくしたい。私のコードは次のとおりです:軸サブプロットyサイズ

import matplotlib.pyplot as plt 
f, axarr = plt.subplots(2, sharex=True,figsize=(15, 12)) 
axarr[0].scatter(x, data , facecolors='none', edgecolors='crimson') 
axarr[0].plot(x, fit, color='g',linewidth=1.5) 
axarr[0].set_ylim([18,10]) 
axarr[1].plot(x,data-fit,color='k',linewidth=width) 
axarr[1].set_ylim([-0.4,0.4]) 
yticks[-1].label1.set_visible(False) 
plt.subplots_adjust(hspace=0.) 

2番目のプロットのサイズを設定するコードはありますか?

答えて

0

this example, using gridspecをご覧ください。私はそれがまさにあなたが望むものだと信じています。以下は、あなたのケースに採用されている例です。 は、最初のリンクでHagnes answerに従うことによっても、x軸

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import gridspec 

# generate some data 
x = np.arange(0, 10, 0.2) 
y = np.sin(x) 

# plot it 
fig = plt.figure(figsize=(8, 6)) 
gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1]) 
ax0 = plt.subplot(gs[0]) 
ax1 = plt.subplot(gs[1], sharex=ax0) # <---- sharex=ax0 will share ax1 with ax2 
ax0.plot(x, y) 
ax1.plot(y, x) 

plt.show() 

あるいはさらに簡単に共有するために編集:すべての

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0, 10, 0.2) 
y = np.sin(x) 

f, (a0, a1) = plt.subplots(2,1, gridspec_kw = {'height_ratios':[1, 3]}, sharex=True) # <---- sharex=True will share the xaxis between the two axes 
a0.plot(x, y) 
a1.plot(y, x) 
plt.show() 

enter image description here

+0

まずあなたの答えをありがとう! はい、私はこれを知っていますが、2つのプロットはx軸を共有していません。私は 'sharex'オプションを取得し、プロットのサイズを設定する方法があるのだろうかと思います。 –

+0

あなたは大歓迎です!私のx軸を共有する私の更新答えを見てください。また、 'GridSpec'を必要としない、より簡単なコードスニペットを追加しました。 – pathoren

+0

完璧!これはまさに私が探していたものです。 –

関連する問題