如何在Matplotlib上叠加

时间:2019-02-23 02:42:35

标签: matplotlib plot

我想使用matplotlib在内部绘制两个点的三角形。这是我正在使用的代码:

plt.figure()
triangleEdges = np.array([[0,0],[1,0],[0.5,0.5*np.sqrt(3)]])
colors = ['red', 'green', 'blue']
t1 = plt.Polygon(triangleEdges, facecolor="none", 
              edgecolor='black', linewidth=2)
t1.set_facecolor('xkcd:salmon')
plt.gca().add_patch(t1)

drawSoftmaxPoint('blue',100,np.array([0.2,0.1,0.7]) )
drawSoftmaxPoint('red',100,np.array([0.5,0.1,0.7]))



plt.show()

Picture

根据代码,三角形内应有两个点,但看起来背景覆盖了它们。如何使它们可见?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在多边形中使用alpha和z顺序来实现它(来自matplotlib的文档)。只需尝试将alpha值设置在0到1之间即可检查您是否可以看到自己的点。然后在不同的元素上使用z顺序,以确保多边形的填充最深(最靠后)。 zorder的示例: https://matplotlib.org/gallery/misc/zorder_demo.html

相关问题