Matplotlib 如何在多个打印中隐藏轴

Matplotlib 如何在多个打印中隐藏轴,matplotlib,plot,axis,Matplotlib,Plot,Axis,请问,隐藏右轴和顶轴的代码有什么错 import matplotlib.pyplot as plt fig, ax = plt.subplots(sharex=True, sharey=True, figsize=(10,3)) fig1 = plt.subplot(121) fig2 = plt.subplot(122) # Set width of axes for figures in [fig1, fig2]: # Removing axis for side in

请问,隐藏右轴和顶轴的代码有什么错

import matplotlib.pyplot as plt

fig, ax = plt.subplots(sharex=True, sharey=True, figsize=(10,3))
fig1 = plt.subplot(121)
fig2 = plt.subplot(122)

# Set width of axes
for figures in [fig1, fig2]:
    # Removing axis 
    for side in ['right','top']:
        ax.spines[side].set_visible(False)
plt.show()
这适用于非多重打印:

for side in ['right','top']:
    ax.spines[side].set_visible(False)
编辑的代码:

import matplotlib.pyplot as plt
import seaborn as sns

fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, sharey=True, figsize=(10,3))
fig1 = plt.subplot(121)
ax1.set_xlabel(r'$k$')
ax1.set_ylabel(r'$\omega$', rotation='horizontal')

fig2 = plt.subplot(122)

sns.despine()
plt.show()

[fig1,fig2]中的ax的
。。虽然
fig1
fig2
在这里是误导性的变量名。或者使用seaborn:
sns.sdevene()
图,axs=plt.subplot(nrows=2,sharex=True,sharey=True,figsize=(10,3))并摆脱无关的
plt.subplt
调用。然后在axs.ravel()中为ax设置
。去掉
图1,ax1=plt.subplot(121)
。如果您愿意,
fig,(ax1,ax2)=plt.子图(nrows=2,sharex=True,sharey=True,figsize=(10,3))
侧注,但对于[fig1,fig2]中的数字,请去掉
和['right',top']中的侧注:。移除脊椎只需
sns.skeene()
,无需循环调用。