CS2 = plt.contour(CS, levels=CS.levels[::2], colors="r", origin=origin)
plt.title("Nonsense (3 masked regions)")
plt.xlabel("word length anomaly")
plt.ylabel("sentence length anomaly")
// Make a colorbar for the ContourSet returned by the contourf call.
cbar = plt.colorbar(CS)
After Change
CS2 = ax2.contour(CS, levels=CS.levels[::2], colors="r", origin=origin)
ax2.set_title("Nonsense (3 masked regions)")
ax2.set_xlabel("word length anomaly")ax2.set_ylabel("sentence length anomaly")
// Make a colorbar for the ContourSet returned by the contourf call.
cbar = fig1.colorbar(CS)
cbar.ax.set_ylabel("verbosity coefficient")
// Add the contour line levels to the colorbar
cbar.add_lines(CS2)
fig2, ax2 = plt.subplots()
// Now make a contour plot with the levels specified,
// and with the colormap generated automatically from a list
// of colors.
levels = [-1.5, -1, -0.5, 0, 0.5, 1]
CS3 = ax2.contourf(X, Y, Z, levels,
colors=("r", "g", "b"),
origin=origin,
extend="both")
// Our data range extends outside the range of levels; make
// data below the lowest contour level yellow, and above the
// highest level cyan:
CS3.cmap.set_under("yellow")
CS3.cmap.set_over("cyan")
CS4 = ax2.contour(X, Y, Z, levels,
colors=("k",),
linewidths=(3,),
origin=origin)
ax2.set_title("Listed colors (3 masked regions)")
ax2.clabel(CS4, fmt="%2.1f", colors="w", fontsize=14)
// Notice that the colorbar command gets all the information it
// needs from the ContourSet object, CS3.