[英]How to plot the lines first and points last in matplotlib
I have a simple plot with several sets of points and lines connecting each set. 我有一个简单的情节,有几组连接每组的点和线。 I want the points to be plotted on top of the lines (so that the line doesn't show inside the point).
我希望将点绘制在线的顶部(以便该线不显示在该点内)。 Regardless of order of the
plot
and scatter
calls, this plot comes out the same, and not as I'd like. 无论
plot
和scatter
调用的顺序如何,这个情节都是相同的,而不是我想要的。 Is there a simple way to do it? 有一个简单的方法吗?
import math
import matplotlib.pyplot as plt
def poisson(m):
def f(k):
e = math.e**(-m)
f = math.factorial(k)
g = m**k
return g*e/f
return f
R = range(20)
L = list()
means = (1,4,10)
for m in means:
f = poisson(m)
L.append([f(k) for k in R])
colors = ['r','b','purple']
for c,P in zip(colors,L):
plt.plot(R,P,color='0.2',lw=1.5)
plt.scatter(R,P,s=150,color=c)
ax = plt.axes()
ax.set_xlim(-0.5,20)
ax.set_ylim(-0.01,0.4)
plt.savefig('example.png')
You need to set the Z-order. 您需要设置Z顺序。
plt.plot(R,P,color='0.2',lw=1.5, zorder=1)
plt.scatter(R,P,s=150,color=c, zorder=2)
Check out this example. 看看这个例子。 http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html
http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.