Reputation: 6668
Is it possible to create a contourplot in Matplitlib with every n-th line a different color then the rest? I would like to have this because this less contourlines are showing not enough detail, and all the same color makes it too crowded. For example:
Upvotes: 1
Views: 284
Reputation: 6668
Yes, you can. You have to specify the colors for each level:
levels = np.logspace(0, np.log10(Z.max()), 100 )[30:80]
color_levels = ['r' if (i+5) % 10 == 0 else 'k' for i in range(len(levels))]
pyplot.contour(X, Y, Z, locator=ticker.LogLocator(), colors=color_levels, levels=levels, lw=2, norm=colors.LogNorm(), vmin=1, vmax=Z.max())
Herein is Z
the results of the np.histogram2d()
. The underlying histogram2d is plotted with imshow
. The [30:80]
slice on the levels is to prevent cluttering in the middle and edges of the image.
Of course you can edit the % 10
in the definition of color_levels
to every integer of your liking.
This results in:
Upvotes: 4