当前位置:网站首页>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
边栏推荐
- Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe
- C language structure - learning 27
- 新知识:Monkey 改进版之 App Crawler
- C language string and pointer - learning 25
- C language bit operation - learning 26
- Defect detection, introduction to Halcon case.
- [project training] verification notes
- jvm: 线程上下文类加载器(TheadContextClassLoader)
- 【项目实训】微信公众号模板消息推送
- [project training] wechat official account to obtain user openid
猜你喜欢

VM tools fail in VMware? Install VM tools using Ali image source

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

Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe

A knowledge map (super dry goods, recommended collection!)

Jmeter接口测试之常用断言

Chapter V - Fund professional ethics

Defect detection, introduction to Halcon case.

中创专利|中国5G标准必要专利达1.8万项,尊重知识产权,共建知识产权强国

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

Nat. Comm. | supercomputing +ai: providing navigation for natural product biosynthesis route planning
随机推荐
Websocket server practice
Lambda intermediate operation flatmap
Matlab 基础04 - 冒号Colon operator “:”的使用和复杂应用详析
Chapter V - Fund professional ethics
一文get,最容易碰上的接口自动化测试问题汇总
Uniapp gets the instance of the previous page
只会基础的功能测试的我,被炒鱿鱼了····
【项目实训】微信公众号获取用户openid
【项目实训】微信公众号模板消息推送
【项目实训】jwt
flowable 工作流
Lambda创建流
Learn to crawl steadily 07 - detailed explanation of how to use XPath
jmeter 性能测试用 csv,这个坑有些扯蛋
The 14th five year plan and investment feasibility study report of global and Chinese hydraulic ester base oil industry 2022 ~ 2028
【项目实训】校验注解
'virtue and art' in the field of recurrent+transformer video recovery
Vue3+ts+node creates personal blog (database design)
Flowable workflow
C language pointer and array - learning 23