简体   繁体   中英

Contourplot matplotlib with every n-th line a different color

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: 银河没有花哨的轮廓线

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:

红色轮廓线的银河

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM