Matplotlib 框架不可见

Matplotlib Frame Invisible

我的图中我的轴的框架是不可见的。我尝试了 ax.spines.set_visible(True)、ax.axis("on") 等,但似乎没有任何效果。您可以在下面找到我尝试绘制的特定图的代码以及我在开始时使用的设置。任何人都知道如何使围绕轴的框架可见?我检查了已经在 Whosebug 上的解决方案,但它们对我也不起作用。谢谢

    import matplotlib as mpl
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    plt.style.use(['seaborn-white','seaborn-paper'])
    import seaborn as sns
    sns.set(font='serif')

    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212, sharex=ax1)

    ax1.set_facecolor("white")
    ax1.axhline(19, color='r', label='$T_{lim}$')
    ax1.axhline(23, color='r')
    ax1.plot(Tair, color='b', linewidth=1, label='$T_{air}$')
    ax1.plot(Tout, color='m', linewidth=1, label='$T_{out}$')
    ax1.set_ylabel('T [°C]', fontsize=15)
    ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    ax1.set_xlim([0, 1440 * (day + 1)])
    ax1.set_xlabel('Time [quarters]', fontsize=15)

    ax2.set_facecolor("white")
    ax2.plot(u_phys, color='b', linewidth=1, label='$u$')
    ax3 = ax2.twinx()
    ax3.plot(price, color='g', linewidth=1, label='$p$')
    ax3.grid(b=False)
    ax3.set_ylabel('Price [€c / kWh]', fontsize=15, color='g')
    ax3.tick_params('y', colors='g')
    ax2.set_xlabel('Time [quarters]', fontsize=15)
    ax2.set_ylabel('Power [kW]', fontsize=15, color='b')
    ax2.tick_params('y', colors='b')
    ax2.set_xlim([0, 1440 * (day + 1)])
    ax2.set_ylim(0, 3.2)
    ax2.set_xticks(np.arange(1440 * (day + 1))[::1440])
    ax2.set_xticklabels(np.arange(day + 1))
    ax2.set_yticks(np.arange(self.n_actions + 1))
    ax2.set_yticklabels(np.array([0, 1, 2, 3, 4]))
    ax2.xaxis.set_visible(True)
    ax1.xaxis.set_visible(True)
    fig.subplots_adjust(left=0.09, wspace=0, hspace=0.26, right=0.88, bottom=0.09, top=0.97)

你在这里混合了很多风格。最好选择 seaborn 风格或 matplotlib 风格,并且只使用其中一种来定义风格。 由于您似乎实际上并不需要 seaborn,因此您可以完全忽略它。

import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

plt.style.use(['seaborn-white','seaborn-paper'])
plt.rcParams["font.family"] = "serif"