无法使用Matplotlib 2.2.2中的contourf更改阴影密度

3
我想使用Matplotlib v2.2.2和contourf()函数更改图案线的密度(具体来说,我想增加密度)。我已经阅读到,通过增加图案图形的使用次数(例如,将x替换为xx),可以增加图案的密度。然而,这种改变对我没有任何影响。我的后端是Qt5Agg,我正在使用Python v3.6.4。
import matplotlib.pyplot as plt
import numpy             as np

def main():
    x = np.arange( 0, 1.01, 0.01 )
    X, Y = np.meshgrid( x, x )
    Z = X + Y

    fig, (ax1, ax2) = plt.subplots( 1, 2 )
    ax1.contourf( X, Y, Z, [1,2], colors='none', hatches='x' )
    ax2.contourf( X, Y, Z, [1,2], colors='none', hatches='xx' )

    plt.show()

main()

这将产生输出结果:

hatch density example

可能的重复:

这个问题已经有7年历史了,需要定义一个自定义类。这仍然是最好的选择吗?

这个问题基本上就是我要问的,但是MWE有点复杂,并且没有吸引到任何答案。

1个回答

10

通常情况下,增加阴影线的密度是没有问题的。这可以通过重复阴影线图案来实现。例如://////

在这里,您有两个轮廓区域/级别。因此需要两种阴影线。

import matplotlib.pyplot as plt
import numpy             as np

def main():
    x = np.arange( 0, 1.01, 0.01 )
    X, Y = np.meshgrid( x, x )
    Z = X + Y

    fig, (ax1, ax2) = plt.subplots( 1, 2 )
    ax1.contourf( X, Y, Z, [1,2], colors='none', hatches=['/',None] )
    ax2.contourf( X, Y, Z, [1,2], colors='none', hatches=['//',None] )

    plt.show()

main()

enter image description here


当然没错。谢谢! - David M.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接