2016-10-19 4 views
0

で3つのグラフ左側の2及び1を有するときに共有は軸。私は次のコードを持っています:matplotlibの:私は、次のグラフを持って右

self.fig_part_1 = plt.figure() 
self.plots_part_1 = [ 
    plt.subplot(221), 
    plt.subplot(223), 
    plt.subplot(122), 
] 

どうすればいいですか?結局、私はプロット221の軸xの数を表示したくありません。

答えて

1

(これは主に@H。牧師へのコメントであるが、私はよりよいコードのフォーマットを取得するための「答え」として投稿)

サブプロットを手動で追加する方が良いと思います。今実装しているので、2つの軸が分かりやすくなります。重なり合った軸合わせや一般的な混乱にも問題があります。最初に図を作成してから軸を1つずつ追加する方が良いと思います。この方法では、現在の図をplt.figure(self.f.number)で「更新」する必要があります。 fig_N

import matplotlib.pyplot as plt 

fig1 = plt.figure() 
# fig2 = plt.figure() # more figures are easily accessible 
# fig3 = plt.figure() # more figures are easily accessible 

ax11 = fig1.add_subplot(221) # add subplot into first position in a 2x2 grid (upper left) 
ax12 = fig1.add_subplot(223, sharex=ax11) # add to third position in 2x2 grid (lower left) and sharex with ax11 
ax13 = fig1.add_subplot(122) # add subplot to cover both upper and lower right, in a 2x2 grid. This is the same as the rightmost panel in a 1x2 grid. 
# ax21 = fig2.add_subplot(211) # add axes to the extra figures 
# ax21 = fig2.add_subplot(212) # add axes to the extra figures 
# ax31 = fig3.add_subplot(111) # add axes to the extra figures 
plt.show() 
+0

私はあなたの答えがよりクリーンだと思うので、私はそれを検証します。当時はありがとうございました。 – lmiguelvargasf

1

ただ、オプションsharex=Trueで、すべての軸を定義するためにplt.subplotsplt.subplotは異なる)を使用します。

f, axes = plt.subplots(2,2, sharex=True) 
plt.subplot(122) 
plt.show() 

注大きなサブプロットの配列を持つ2番目の呼び出しは、前のものを重ねること。

Example(原因評判に画像を表示することができませんでした...)

+0

それは、これが動作するように起こっているようだが、私は自分のコードにいくつかの数字を持っているので、実際に何が起こっているか 'plt.subplot(122)は'別の数字を重ねているということです。 – lmiguelvargasf

+0

私はそれを解決しました。私は、 'plt.subplot(122)'を呼び出す前にオーバーレイしたい図形 'plt.figure(self.f.number)'を選択しなければならなかったようです。 – lmiguelvargasf

+0

真実、私はそれについて考えなかった。また、いくつかの数値を扱う場合は、 'f.add_subplot(122)'でsubplotを呼び出すことができます.fは 'plt.subplots()'のタプル出力の最初の要素です。 –

関連する問題