Python 是否有一个matplotlib.pyplot代码,可以在不使用';轴。网格';密码?

Python 是否有一个matplotlib.pyplot代码,可以在不使用';轴。网格';密码?,python,matplotlib,subplot,Python,Matplotlib,Subplot,我正在尝试获得一组类似于此代码结果的子图: import matplotlib.pyplot as plt import numpy as np import matplotlib.gridspec as gridspec fig = plt.figure(tight_layout=True) gs = gridspec.GridSpec(2, 2) ax = fig.add_subplot(gs[0, :]) ax.plot(np.arange(0, 1e6, 1000)) ax.set_

我正在尝试获得一组类似于此代码结果的子图:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec

fig = plt.figure(tight_layout=True)
gs = gridspec.GridSpec(2, 2)

ax = fig.add_subplot(gs[0, :])
ax.plot(np.arange(0, 1e6, 1000))
ax.set_ylabel('YLabel0')
ax.set_xlabel('XLabel0')

for i in range(2):
    ax = fig.add_subplot(gs[1, i])
    ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1))
    ax.set_ylabel('YLabel1 %d' % i)
    ax.set_xlabel('XLabel1 %d' % i)
    if i == 0:
        for tick in ax.get_xticklabels():
            tick.set_rotation(55)
fig.align_labels()  # same as fig.align_xlabels(); fig.align_ylabels()

plt.show()
我想知道是否有一种替代代码,不必使用
matplotlib.gridspec
,而是完全使用
matplotlib.pyplot
,这样我就可以得到这个结果

我最初尝试了以下代码的许多变体:

plt.subplot(111)
plt.plot(I_123, nu_123, 'o', markersize=5)
plt.plot(I_123, F_123)
plt.grid(True)
plt.xlabel('Current/A', size='15')
plt.ylabel('Frequency/Hz', size='15')
plt.title('Plot for all plot points', size='25')

plt.subplot(221)
plt.plot(B_glycerine, nu_glycerine, 'o', markersize=5, color='indigo')
plt.plot(B_glycerine, Fglyc, color='red')
plt.grid('True')
plt.tick_params(labelsize='20')
plt.xlabel('Magnetic Field Strength/T', size='24')
plt.ylabel(r'Frequency/$\times$10MHz', size='24')
plt.title('NMR plot for glycerine', size='25')

plt.subplot(222)
plt.plot(B_ptfe, nu_ptfe, 'o', markersize=5, color='indigo')
plt.plot(B_ptfe, Fptfe, color='red')
plt.grid('True')
plt.tick_params(labelsize='20')
plt.xlabel('Magnetic Field Strength/T', size='24')
plt.ylabel(r'Frequency/$\times$10MHz', size='24')
plt.title('NMR plot for PTFE', size='25')

但我只看到两个子地块,其中一个子地块总是被完全排除在外,没有找到任何方法来纠正这一点。我不想使用第一段代码,因为它可能会导致我必须更改其余代码,使其对我有意义,因此如果有任何其他方法可以使用
matplotlib.pyplot
,我们将不胜感激。

如果您想要相同的轴配置,您可以执行以下任一操作:

plt.子地块(211)
(...)
小地块(223)
(...)
plt.子地块(224)
(...)

gs=gridspec.gridspec(2,2)
ax1=plt.子批次(gs[0,:])
(...)
ax2=plt.子批次(gs[1,0])
(...)
ax3=plt.子批次(gs[1,1])
(...)

如果需要相同的轴配置,可以执行以下操作之一:

plt.子地块(211)
(...)
小地块(223)
(...)
plt.子地块(224)
(...)

gs=gridspec.gridspec(2,2)
ax1=plt.子批次(gs[0,:])
(...)
ax2=plt.子批次(gs[1,0])
(...)
ax3=plt.子批次(gs[1,1])
(...)

或者您可以使用切片指定范围:

ax1=plt.子批次(2,2,1,2))
ax2=plt.子批次(2,2,3)
ax3=plt.子批次(2,2,4)

这样做的好处是使用相同的gridspec,因此
受约束的\u布局将继续工作。

或者您可以使用切片指定范围:

ax1=plt.子批次(2,2,1,2))
ax2=plt.子批次(2,2,3)
ax3=plt.子批次(2,2,4)

这样做的好处是使用相同的gridspec,因此
受约束的_布局将继续工作。

gridspec
有什么问题?很难准确理解您的问题是什么
gridspec
没有什么问题,我只是想问是否有其他方法可以使用
pyplot
,这样我就可以让代码看起来一致,这样我个人就能更好地阅读和理解它。
gridspec
有什么问题?很难准确理解您的问题是什么,
gridspec
没有问题,我只是想问是否有其他方法可以使用
pyplot
,这样我就可以让代码看起来一致,这样我个人就可以更好地阅读和理解它。非常感谢!非常感谢你!