我有以下代碼:
fig = plt.figure(figsize = (16,9))
ax1 = plt.subplot(3, 2, 1)
ax2 = plt.subplot(3, 2, 2)
ax3 = plt.subplot(3, 2, 3)
ax4 = plt.subplot(3, 2, 4)
ax5 = plt.subplot(3, 1, 3)

但是,我希望將第三行(跨越兩列的圖)的高度減少一半。我該怎么做呢?
我知道這篇文章:
uj5u.com熱心網友回復:
您鏈接到的帖子有可以幫助您的答案,但現在最簡單的方法(自 matplotlib-3.3.0 起)可能是使用
這將axes作為Axes您給它的名稱的字典回傳,因此您可以使用例如
axes["A"].plot([1, 2, 3], [1, 2, 3])
(您也可以像這樣“雙重堆疊”您的馬賽克以獲得相同的效果,而無需使用gridspec_kw)
fig, axes = plt.subplot_mosaic("AB;AB;CD;CD;EE")
如果由于某種原因您不想(或不能)使用suplot_mosaic,那么您可以GridSpec直接使用(例如此處)。
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs = GridSpec(nrows=3, ncols=2, figure=fig, height_ratios=[1, 1, 0.5])
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 0])
ax4 = fig.add_subplot(gs[1, 1])
ax5 = fig.add_subplot(gs[2, :])
這會給你同樣的東西。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/495130.html
標籤:Python matplotlib 高度 子情节
上一篇:獲取箱中心直方圖python
