首页 > 解决方案 > 同一轮廓的不同线条样式

问题描述

我有一个等高线图,对于固定值,有两个单独的等高线。我想将这两个轮廓彼此区分开来,例如一个带有虚线的轮廓和一个带有简单线条的轮廓。我正在使用 python 和 Matplotlib。

谢谢!

在下图中,我希望将红色轮廓之一(对应于值 1)用虚线表示。 在此处输入图像描述

标签: pythonmatplotlibcontour

解决方案


阅读 的文档contour(),您会发现可以像使用颜色列表一样使用线型列表。

这里

linestyles{None, 'solid', 'dashed', 'dashdot', 'dotted'}, optional

    Only applies to contour.

    If linestyles is None, the default is 'solid' unless the lines are monochrome. In that case, negative contours will take their linestyle from rcParams["contour.negative_linestyle"] (default: 'dashed') setting.

    linestyles can also be an iterable of the above strings specifying a set of linestyles to be used. If this iterable is shorter than the number of contour levels it will be repeated as necessary.

推荐阅读