【发布时间】:2022-01-15 12:28:42
【问题描述】:
我有以下代码:
fig1 = plt.figure(figsize=(10, 10))
# Objeto
ax1 = fig1.add_subplot(3, 1, 1)
ax1.plot(xL, fL, 'k')
ax1.set_xlim(-0.04, 0.04)
ax1.set_ylim(0, 2.1)
ax1.set_title('Objeto')
ax1.set_xlabel('d (cm)')
ax1.set_ylabel('Intensidade')
ax1.grid(axis='both')
# Echo
ax2 = fig1.add_subplot(3, 1, 2)
tempo = np.arange(0, N0) * dT
CurvaT2 = exp(-tempo / T2)
ax2.plot(tempo, Ms[0, :], 'b', tempo, Ms[1, :], 'k-')
ax2.set_title('Echo') # 'FontSize',12
ax2.set_xlabel('Tempo (ms)')
ax2.set_ylabel('Intensidade')
ax2.grid(axis='both')
# Módulo Magnetização
ax3 = fig1.add_subplot(3, 1, 3)
ax3.plot(tempo, Mod, 'k', tempo, CurvaT2, 'g--')
ax3.set_title('Módulo Magnetização') # 'FontSize',12
ax3.set_xlabel('Tempo (ms)')
ax3.set_ylabel('Intensidade')
ax3.grid(axis='both')
如您所见,标题和 xlabels 混淆了。我能做些什么来解决这个问题?
【问题讨论】:
-
通常,最后调用
plt.tight_layout()适用于这种情况。如果没有,plt.subplots_adjust(hspace=0.2)左右可能会起作用(建议使用plt.tight_layout(),以防它产生良好的结果,因为它会在更改情节后继续工作)。
标签: python matplotlib