Python 显示不同比例的重叠额外标记和标签

Python 显示不同比例的重叠额外标记和标签,python,matplotlib,Python,Matplotlib,我试图用matplotlib绘制多个子图,但在显示额外比例时遇到问题。我想ax.label_outer()只显示看起来像的外部标签,但是在x轴和y轴上都有一组额外的记号,都是0-1,我不需要。它们是默认值吗?从哪里来?有人能告诉我怎么摆脱它们吗 #%% %matplotlib inline import matplotlib.pyplot as plt import numpy as np %config InlineBackend.figure_format ='retina' #%%

我试图用matplotlib绘制多个子图,但在显示额外比例时遇到问题。我想
ax.label_outer()
只显示看起来像的外部标签,但是在x轴和y轴上都有一组额外的记号,都是0-1,我不需要。它们是默认值吗?从哪里来?有人能告诉我怎么摆脱它们吗

#%%
%matplotlib inline 
import matplotlib.pyplot as plt
import numpy as np

%config InlineBackend.figure_format ='retina'

#%%
nrows, ncols = 2, 3

# https://stackoverflow.com/questions/28070906/loop-over-2d-subplot-as-if-its-a-1-d
fig, axes = plt.subplots(nrows = nrows, ncols=ncols, figsize=(20,10), sharex=True, sharey=True)
plt.subplots_adjust(hspace=.4, wspace=.2, top=.90)
num = 1

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
num = 1

for ax in axes.flatten()[:5]:

    stationName = 'Title - ' + str(num)

    ax = fig.add_subplot(nrows, ncols, num)
    #plt.setp(ax.get_xticklabels(), visible=False)
    #plt.setp(ax.get_yticklabels(), visible=False)


    ax.plot(x,y)
    ax.yaxis.grid(color='gray', linestyle='dashed')
    #ax.xaxis.set_tick_params(length=0)
    #ax.yaxis.set_tick_params(length=0)
    plt.title(stationName, loc='center', fontsize=15, fontweight=0, color='green' )
    num = num + 1
fig.delaxes(axes[-1,-1])
fig.suptitle('Temperature', fontsize=20)


for ax in axes.flat:
    ax.set(xlabel='Years', ylabel='Records') 

for ax in axes.flat:
    ax.label_outer()   
# https://towardsdatascience.com/all-your-matplotlib-questions-answered-420dd95cb4ff    
plt.show();


@ImportanceofBeingEarnest的回答对我很有帮助,我只需编辑我如何创建标题。我的新代码是:

#%%
%matplotlib inline 
import matplotlib.pyplot as plt
import numpy as np

%config InlineBackend.figure_format ='retina'

#%%
nrows, ncols = 2, 3

# https://stackoverflow.com/questions/28070906/loop-over-2d-subplot-as-if-its-a-1-d
fig, axes = plt.subplots(nrows = nrows, ncols=ncols, figsize=(20,10), sharex=False, sharey=True)
plt.subplots_adjust(hspace=.4, wspace=.2, top=.90)
num = 1

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
num = 1

for ax in axes.flatten()[:5]:

    stationName = 'Title - ' + str(num)
    ax.plot(x,y,color='blue')
    ax.plot(x,-y,color='red' )
    ax.yaxis.grid(color='gray', linestyle='dashed')
    ax.set(xlabel='Years', ylabel='Records') 
    ax.set_title(stationName, fontdict={'fontsize': 15, 'fontweight': 0, 'color':'green', 'ha':'center'}) 
    num = num + 1
fig.delaxes(axes[-1,-1])
fig.suptitle('Temperature', fontsize=20)

plt.show();

对于
中已存在的每个轴,似乎可以在该现有轴的相同位置添加另一个轴(通过
。添加子地块
)。所以每个子地块位置有两个轴。谢谢!这很管用,但我不得不稍微改变一下我写标题的方式。我能感谢你给了你荣誉吗?