Я думаю о графике, который содержит 3 строки и 4 столбца, где:
Есть 3 зависимых переменных для построения графика: Y1
, Y2
и Y3
, в отличие от общего X
независимая переменная, для 4 случаев обучения:

В этой ситуации:
1) совместное использование y
ось при переходе от case i
к case i+1
2) совместное использование оси x
в пределах case i
Таким образом, в принципе, можно подумать, что следующий кодсоздаст желаемый график (результат показан на верхнем изображении):
fig, axes = plt.subplots(ncols=4, nrows=3,\
sharex=True, sharey=True,\
subplot_kw=dict(adjustable='box-forced'))
, где adjustable='box-forced'
просто для того, чтобы убедиться, что вспомогательные участки возведены в квадрат, как объяснено здесь .
Когда я пытаюсь построить Y1
против X
для случая 1:
import numpy as np
import matplotlib.pyplot as plt
import sys
fig, axes = plt.subplots(ncols=4, nrows=3,\
sharex=True, sharey=True,\
subplot_kw=dict(adjustable='box-forced'))
pad = 5
axes[0][0].annotate('Case 1', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][1].annotate('Case 2', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][2].annotate('Case 3', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][3].annotate('Case 4', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
#
axes[0][0].set_ylabel('Y1', fontsize=10)
axes[1][0].set_ylabel('Y2', fontsize=10)
axes[2][0].set_ylabel('Y3', fontsize=10)
E_C_I = np.array([-941.23658347, -941.23685494, -941.23467666])
V_C_I = np.array([ 61.66341, 62.342903, 67.9311515])
E_14 = np.array([-941.22938469, -941.23583586, -941.23605613])
V_14 = np.array([ 54.65693125, 58.47115725, 60.8626545 ])
P_C_I = np.array([ 2.20068119, 1.33328211, -4.28370285])
P_14 = np.array([ 8.16605135, 7.54737315, 0.3909309 ])
axes[0][0].scatter(V_C_I, E_C_I, marker='^', color='red', label='Calcite I')#, s=100)
axes[0][0].scatter(V_14, E_14, marker='o', color='green', label='Calcite I')#, s=100)
axes[0][0].set_ylim(bottom=-941.238, top=-941.229)
plt.tight_layout()
axes[0][0].ticklabel_format(useOffset=False)
plt.show()
sys.exit()
Все выглядит нормально:

Я вынудил график axes[0][0].set_ylim(bottom=-941.238, top=-941.229)
Когда я пытаюсь построить Y2
против X
для Case 1
, следующий код должен работать: я в основном делаю то же, что и раньше, но аддиng axes[1][0]
инструкция построения:
import numpy as np
import matplotlib.pyplot as plt
import sys
fig, axes = plt.subplots(ncols=4, nrows=3,\
sharex=True, sharey=True,\
subplot_kw=dict(adjustable='box-forced'))
pad = 5
axes[0][0].annotate('Case 1', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][1].annotate('Case 2', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][2].annotate('Case 3', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
axes[0][3].annotate('Case 4', xy=(0.5, 1), xytext=(0, pad),
xycoords='axes fraction', textcoords='offset points',
size='large', ha='center', va='baseline')
#
axes[0][0].set_ylabel('Y1', fontsize=10)
axes[1][0].set_ylabel('Y2', fontsize=10)
axes[2][0].set_ylabel('Y3', fontsize=10)
E_C_I = np.array([-941.23658347, -941.23685494, -941.23467666])
V_C_I = np.array([ 61.66341, 62.342903, 67.9311515])
E_14 = np.array([-941.22938469, -941.23583586, -941.23605613])
V_14 = np.array([ 54.65693125, 58.47115725, 60.8626545 ])
P_C_I = np.array([ 2.20068119, 1.33328211, -4.28370285])
P_14 = np.array([ 8.16605135, 7.54737315, 0.3909309 ])
axes[0][0].scatter(V_C_I, E_C_I, marker='^', color='red', label='Calcite I')#, s=100)
axes[0][0].scatter(V_14, E_14, marker='o', color='green', label='Calcite I')#, s=100)
axes[0][0].set_ylim(bottom=-941.238, top=-941.229)
axes[1][0].scatter(V_C_I, P_C_I, marker='^', color='red', label='Calcite I')#, s=100)
axes[1][0].scatter(V_14, P_14, marker='o', color='green', label='Calcite I')#, s=100)
axes[1][0].set_ylim(bottom=-4.4, top=8.4)
plt.tight_layout()
axes[0][0].ticklabel_format(useOffset=False)
plt.show()
sys.exit()
В результате график axes[0][0]
изменил свой масштаб и, следовательно, данные не отображаются:

Я заставил и axes[0][0]
, и axes[0][1]
показать регион, где действительно есть данные:
axes[0][0].set_ylim(bottom=-941.238, top=-941.229)
axes[1][0].set_ylim(bottom=-4.4, top=8.4)
Однако на axes[0][0]
данные не отображаютсясюжет.Почему это происходит?
Обновление: Разница между sharey='row'
и sharey=True
была разъяснена в отличном ответе @ DavidG.Однако я проверил разницу между sharex='col'
и sharex=True
и заметил, что:
fig, axes = plt.subplots(ncols=4, nrows=3,\
sharex=True, sharey='row',\
subplot_kw=dict(adjustable='box-forced'))
производит следующее:

Однако, вид
fig, axes = plt.subplots(ncols=4, nrows=3,\
sharex='col', sharey='row',\
subplot_kw=dict(adjustable='box-forced'))
оставляет некоторое пространство между столбцами и нарушает объявление adjustable='box-forced'
для квадратов, которые должны быть возведены в квадрат:

Мне было интересно, почему это происходит?