【问题标题】:highlight single contour line突出显示单个轮廓线
【发布时间】:2012-12-25 04:47:18
【问题描述】:

我正在制作一个简单的等高线图,我想通过加粗和更改颜色来突出显示零线。

cs = ax1.contour(x,y,obscc)
ax1.clabel(cs,inline=1,fontsize=8,fmt='%3.1f')

我如何实现这一目标? 谢谢:-)

【问题讨论】:

    标签: numpy python-2.7 matplotlib


    【解决方案1】:

    HTH -- 这基本上是取自matplotlib docs 的轮廓示例,只是修改了水平线

    contour 方法返回的对象在其collections 属性中包含对等高线的引用。 等高线只是常见的 LineCollections。

    在以下代码 sn-p 中,对等高线图的引用位于 CS(即您的问题中的 cs):

    CS.collections[0].set_linewidth(4)           # the dark blue line
    CS.collections[2].set_linewidth(5)           # the cyan line, zero level
    CS.collections[2].set_linestyle('dashed')
    CS.collections[3].set_linewidth(7)           # the red line
    CS.collections[3].set_color('red')
    CS.collections[3].set_linestyle('dotted')
    
    type(CS.collections[0])
    # matplotlib.collections.LineCollection
    

    如果您没有明确指定级别,以下是查找级别的方法:

    CS.levels
    array([-1. , -0.5,  0. ,  0.5,  1. ,  1.5])
    

    还有很多功能可以格式化单个标签:

    CS.labelCValueList    CS.labelIndiceList    CS.labelTextsList
    CS.labelCValues       CS.labelLevelList     CS.labelXYs
    CS.labelFmt           CS.labelManual        CS.labels
    CS.labelFontProps     CS.labelMappable      CS.layers
    CS.labelFontSizeList  CS.labelTexts
    

    【讨论】:

    • 谢谢 :-) 这会很好。
    猜你喜欢
    • 1970-01-01
    • 2017-07-17
    • 2015-06-25
    • 2011-07-09
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 2019-02-23
    相关资源
    最近更新 更多