// You can set negative contours to be solid instead of dashed:
matplotlib.rcParams["contour.negative_linestyle"] = "solid"
plt.figure()
CS = plt.contour(X, Y, Z, 6,
colors="k", // negative contours will be dashed by default
)
plt.clabel(CS, fontsize=9, inline=1)
After Change
colors="k", // negative contours will be dashed by default
)
ax.clabel(CS, fontsize=9, inline=1)
ax.set_title("Single color - negative contours solid")
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// And you can manually specify the colors of the contour
fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z, 6,
linewidths=np.arange(.5, 4, .5),
colors=("r", "green", "blue", (1, 1, 0), "//afeeee", "0.5")
)
ax.clabel(CS, fontsize=9, inline=1)
ax.set_title("Crazy lines")
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Or you can use a colormap to specify the colors; the default
// colormap will be used for the contour lines
fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation="bilinear", origin="lower",
cmap=cm.gray, extent=(-3, 3, -2, 2))
levels = np.arange(-1.2, 1.6, 0.2)
CS = ax.contour(Z, levels, origin="lower", cmap="flag",
linewidths=2, extent=(-3, 3, -2, 2))
// Thicken the zero contour.
zc = CS.collections[6]
plt.setp(zc, linewidth=4)
ax.clabel(CS, levels[1::2], // label every second level
inline=1, fmt="%1.1f",
cmap="flag", fontsize=14)
// make a colorbar for the contour lines
CB = fig.colorbar(CS, shrink=0.8, extend="both")
ax.set_title("Lines with colorbar")
// We can still add a colorbar for the image, too.
CBI = fig.colorbar(im, orientation="horizontal", shrink=0.8)