无法在 Matplotlib 2.2.2 中使用 contourf 更改填充密度
Cannot change hatch density using contourf in Matplotlib 2.2.2
我想使用 Matplotlib v2.2.2 和 contourf()
函数更改阴影线的密度(具体来说,我想增加密度)。我读到可以通过增加使用填充图形的次数来增加填充密度(例如将x
替换为xx
)。但是,这种变化对我没有影响。我的后端是 Qt5Agg
,我正在使用 Python v3.6.4.
MWE:
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()
产生输出
可能重复:
This question 7 岁,需要自定义 class。这仍然是最好的选择吗?
This question 基本上正是我要问的,但是 MWE 有点复杂,没有吸引任何答案。
孵化的密一些一般是没有问题的。这确实是通过重复阴影图案来完成的。例如。 /
, //
, ///
.
在这里,你有两个轮廓regions/levels。因此你需要两个舱口。
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()
我想使用 Matplotlib v2.2.2 和 contourf()
函数更改阴影线的密度(具体来说,我想增加密度)。我读到可以通过增加使用填充图形的次数来增加填充密度(例如将x
替换为xx
)。但是,这种变化对我没有影响。我的后端是 Qt5Agg
,我正在使用 Python v3.6.4.
MWE:
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()
产生输出
可能重复:
This question 7 岁,需要自定义 class。这仍然是最好的选择吗?
This question 基本上正是我要问的,但是 MWE 有点复杂,没有吸引任何答案。
孵化的密一些一般是没有问题的。这确实是通过重复阴影图案来完成的。例如。 /
, //
, ///
.
在这里,你有两个轮廓regions/levels。因此你需要两个舱口。
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()