如何先绘制线,最后绘制点
我有一个简单的图,其中有几组点和连接每组的线。我希望将点绘制在线条的顶部(以便线条不会显示在点内)。无论 plot
和 scatter
调用的顺序如何,该图的结果都是一样的,而不是我想要的那样。有简单的方法吗?
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')
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. 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')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置 Z 顺序。
看看这个例子。
http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html
You need to set the Z-order.
Check out this example.
http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html