@eaaaui (Taku Taku)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

GridSpecで作成した2次元データプロットにカラーバーを付けたい!

GridSpecで作成した2次元データプロットにカラーバーを付けたい!

共通のX軸に対して、Y軸を-2~10は線形で、10~1000は対数で表示する2次元マップを作りました。
この右側にカラーバーを表示させたいのですが、どなたかご教授お願い致します!

発生している問題・エラー

image.png

該当するソースコード

F = plt.figure(figsize=(4,6))
gs = gridspec.GridSpec(2,1,height_ratios=(1.4,1))
plt.subplots_adjust(hspace = 0.01)

ax1 =  F.add_subplot(gs[0, 0])
ax2 =  F.add_subplot(gs[1, 0])

ax1.contourf(X,Y,Z)
ax1.set_ylim(10.1,1000)
ax1.set_yscale("log")
plt.setp(ax1.get_xticklabels(), visible=False)

ax2.contourf(X,Y,Z)
ax2.set_ylim(-2,10.1)

plt.plot()
0 likes

1Answer

fig.colorbar(Z, ax=[ax1, ax2])

で右側にカラーバーを付けられると思います。
また、グラフとカラーバーが重なってしまう場合は、

F = plt.figure(figsize=(4,6), constrained_layout=True)

とすると、重ならずに表示できるようです。
参考資料

0Like

Comments

  1. @eaaaui

    Questioner

    わかりやすいご説明、参考資料までありがとうございます!
    無事解決できました!

Your answer might help someone💌