Python:在 scipy 情节之上绘制?(voronoi) [英] Python: plot on top of scipy plot? (voronoi)

查看:71
本文介绍了Python:在 scipy 情节之上绘制?(voronoi)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 voronoi 图(这是一个 scipy 图)的顶部绘图?请注意,我的问题与

how do I plot on top of a voronoi plot (which is a scipy plot)? Note my question is slightly different than here where they explain how to color a voronoi plot

For instance, imagine that I have some more points

points = np.array([[1,2], [3,4], [5,6], [7,8]])

after a first voronoi plot. I would like to add them within the existing plot. How do I do that?

The voronoi plot I' referring to is scipy.spatial.voronoi_plot_2d()

解决方案

I think you can simply reuse plot like this:

import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import voronoi_plot_2d, Voronoi

points = np.array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]])
v = Voronoi(points)
voronoi_plot_2d(v)

p2 = [[0.25, 1], [1, 0.75], [1.75, 0.25], [1.75, 1.75]]
x, y = zip(*p2)

plt.scatter(x, y, color='r')
plt.show()

这篇关于Python:在 scipy 情节之上绘制?(voronoi)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆