the two figures below (I will call the top one Figure 1 and the bottom one Figure 2) were created using the same call to the same function from the Spyder commandline, one immediately after the other. It can be seen that the results of contourf() are inconsistent. The desired result is for the top edge of the contourf result to be truncated by the blue line, as in Figure 1 a), and as far as I can tell, from my code this is how all the plots should be. I do not believe the problem is in the data as I have successfully potted it before (contourf still showed inconsistencies from call to call of the same function, but they were not as egregious as this and it only took me once or twice to get a correct version). Is there anything I can do about this?
Here is the code that creates this plot:
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