[英]How to calculate size of scatter plot's marker in matplotlib
Let's say I create a simple matplotlib scatter plot. 假设我创建了一个简单的matplotlib散点图。
How would I then draw the line between the edges of dots on scatter plot? 然后,我如何在散点图上绘制点边缘之间的线? Meaning that the line would start and end on edges of dots?
这意味着线条会在点的边缘开始和结束?
EDIT: Forgot to add code snippet 编辑:忘记添加代码段
import matplotlib.pyplot as plt
plt.scatter([0, 0, 0], [5, 3, 4], s=250)
plt.scatter([3, 3, 3], [5, 3, 4], s=350)
plt.arrow(0, 5, dx=3, dy=0, width=0.01)
plt.arrow(0, 3, dx=3, dy=0, width=0.01)
plt.arrow(0, 4, dx=3, dy=0, width=0.01)
plt.show()
How do I subtract from dx to connect dots only from edges 如何从dx中减去仅从边连接点
You could finagle with the sizes of the dots, but this is not how one should approach the problem. 您可以使用点的大小进行finagle,但这不是应该如何解决问题的方法。 A better way would be to draw the dots after one draws the lines, so that the dots are placed on top.
更好的方法是在绘制线条后绘制点,以便将点放在顶部。
This can be achieved with zorder . 这可以通过zorder实现。 In your example, this would look like
在您的示例中,这看起来像
import matplotlib.pyplot as plt
plt.scatter([0, 0, 0], [5, 3, 4], s=250, zorder=2)
plt.scatter([3, 3, 3], [5, 3, 4], s=350, zorder=2)
plt.arrow(0, 5, dx=3, dy=0, width=0.01, zorder=1)
plt.arrow(0, 3, dx=3, dy=0, width=0.01, zorder=1)
plt.arrow(0, 4, dx=3, dy=0, width=0.01, zorder=1)
plt.show()
and this produces the plot 这就产生了情节
As an aside, you probably also are not looking for arrow
if you're only looking to draw lines between points. 顺便说一下,如果你只想在点之间画线,你可能也不会寻找
arrow
。 You are just looking for plot
. 你只是在寻找
plot
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.