当前位置:网站首页>Colorize Voronoi Diagram Template
Colorize Voronoi Diagram Template
2022-06-12 01:19:00 【Yangsier】
Stackoverflow
Colorize Voronoi Diagram
https://stackoverflow.com/questions/20515554/colorize-voronoi-diagram/20678647#20678647
IPython Cookbook, Second Edition (2018)
14.5. Computing the Voronoi diagram of a set of points
https://ipython-books.github.io/145-computing-the-voronoi-diagram-of-a-set-of-points/
template
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d
def normalizer(dataArray):
if dataArray.max() - dataArray.min() == 0:
return dataArray
return (dataArray-dataArray.min())/(dataArray.max() - dataArray.min())
def comparisionPlot(columnName0, columnName1, hueColumn, dataDf):
# add 4 distant dummy points to help coloring the edge
# dataPoints = np.append((dataDfNormalized)[['P-MEAN', 'RANK']], [[2,2], [-2,2], [2,-2], [-2,-2]], axis = 0)
# normal version
dataPoints = dataDf[[columnName0, columnName1]]
# plot Voronoi diagrame
vor = Voronoi(dataPoints)
voronoi_plot_2d(vor, show_vertices = True, point_size = 2)
# color list
colorList = []
for regionIndex in range(len(vor.regions)):
if not -1 in vor.regions[regionIndex]:
polygon = [vor.vertices[i] for i in vor.regions[regionIndex]]
if len(polygon) == 0:
colorList += colorList[-1:]
continue
colorList += [np.array(polygon).transpose().min()]
colorList += colorList[-1:]
colorList = normalizer(np.array(colorList))
# colorize
for regionIndex in range(len(vor.regions)):
if not -1 in vor.regions[regionIndex]:
polygon = [vor.vertices[i] for i in vor.regions[regionIndex]]
plt.fill(*zip(*polygon),color=np.repeat(colorList[regionIndex],3))
# fix the range of axes
plt.xlim([-0.2,1.2]), plt.ylim([-0.2,1.2])
plt.show()Question answering
边栏推荐
- Before applying data warehouse ODBC, you need to understand these problems first
- Elementary OJ problem of binary tree
- Article 8: Design of multi-functional intelligent trunk following control system | undergraduate graduation project - [reply and Q & a record of design completion]
- Comparison of OpenCV basic codes of ros2 foxy~galactic~humble
- Such a change in people's understanding of the industrial Internet is not achieved overnight
- 市场监管总局、国家网信办:开展数据安全管理认证工作
- Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
- Unity頂點動畫的陰影實現
- C dynamically calls the static library generated by go
- Interviewer: do you understand redis' shared object pool?
猜你喜欢

Before applying data warehouse ODBC, you need to understand these problems first

Set up NFT blind box mall system | customized development of NFT mall software

Intel trimbert: tailor Bert for trade-offs

I'm fired because I can only test basic functions····

Common assertions for JMeter interface testing

打造Flutter高性能富文本编辑器——渲染篇

网狐游戏服务器-房间配置向导-组件属性与基本配置赋值

Detailed explanation and examples of common parameters of curl

Recursive and non recursive transformation

写代码复现论文的几点建议!
随机推荐
Lambda intermediate operation skip
Devops landing practice drip and pit stepping records - (1)
市场监管总局、国家网信办:开展数据安全管理认证工作
Global and Chinese medical styrene block copolymer industry prospect research and investment planning proposal report 2022-2028
JMeter operation process that can be understood at a glance
手写MapReduce程序详细操作步骤
Crawler case 05 - parsing websites using XPath
Unity顶点动画的阴影实现
Shadow implementation of unity vertex animation
VsCode - 保存文件自动格式化将单引号 ‘ 变成双引号 “ 的问题
Article 6: Design of multi-functional intelligent trunk following control system | undergraduate graduation design - [Key Technology - positioning technology related data (UWB WiFi Bluetooth)]
One article to show you how to understand the harmonyos application on the shelves
Verification code is the natural enemy of automation? Let's see how Ali P7 solved it
Weibull Distribution韦布尔分布的深入详述(1)原理和公式
Lambda intermediate operation limit
C language multidimensional array and pointer - learning 24
[signalr complete series] Implementation of signalr packet communication in net6
Data visualization big screen - big screen cloud minimalist user manual
Lambda create stream
How to guarantee industrial control safety: system reinforcement