不一致图

2024-04-29 05:09:23 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的两个图(我将调用上图1和下图2)是使用从Spyder命令行对同一函数的相同调用创建的,一个接一个。可以看出,contourf()的结果不一致。理想的结果是轮廓图结果的上边缘被蓝线截断,如图1A所示),据我所知,从我的代码来看,所有的图都应该是这样的。我不相信问题出在数据上,因为我之前已经成功地封装了它(contourf仍然显示了同一函数的调用之间的不一致,但它们并没有像这样严重,我只花了一两次就得到了正确的版本)。我能做些什么吗

以下是创建此绘图的代码:

def plot_clay_concentration(cross_sections, bed_profiles, levels):
    assert len(cross_sections) == len(bed_profiles)
    fig, ax_list = plt.subplots(3, 1, sharex=True)
    axis_labels = ["a)", "b)", "c)"]
    for i in range(len(cross_sections)):

        # skip making the middle plot until we have the data for that experiment
        if i == 1:
            continue

        ax = ax_list[i]
        cross_section = cross_sections[i]
        bed_profile = bed_profiles[i]

        x, z, clay_conc = cr.get_cs_plot_input_arrays(cross_section)
        x /= 100
        CS = ax.contourf(x, z, clay_conc, levels = levels, cmap = 'YlOrBr')
        ax.plot(bed_profile["X_cm"] / 100, bed_profile["Z_cm"], label = "Bed Profile")
        z_min = ax.get_ylim()[0]
        ax.set_ylim((z_min, 5))

        ax_label = plt.text(0.01, 0.85, axis_labels[i], transform = ax.transAxes)

    plt.xlabel("Downstream Distance (m)")

    fig.subplots_adjust(right = 0.8)
    cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
    cbar = plt.colorbar(CS, cax = cbar_ax)
    labels = cbar_ax.get_yticklabels()
    new_labels = ['{:.2f}%'.format(float(x.get_text())) for x in labels]
    cbar_ax.set_yticklabels(new_labels)

    t = plt.text(0.035, 0.5, "Depth (cm)", ha = 'center', va = 'center', rotation = 90, transform = fig.transFigure)

    # as long as I don't have data to put in the middle subplot, don't add arbitrary tick labels to it either.
    fig.axes[1].get_yaxis().set_ticks([])

    return fig

Figure 1

enter image description here


Tags: getlabelslenplotfigpltaxprofiles