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

import csv

COUNT_LIMIT = None
SAMPLE_LIMIT = 100

Points = []
with open('cell_info.csv', 'r', encoding='utf_8') as obj_file:
    csv_file = csv.reader(obj_file)
    for cnt, line in enumerate(csv_file):
        if COUNT_LIMIT and cnt >= COUNT_LIMIT:  # 只读取前 k 个点
            break
        Points.append([float(line[1]), float(line[2])])  # make up data points

# 随机抽取 n 个点
if SAMPLE_LIMIT:
    points = np.array([Points[i] for i in np.random.choice(len(Points), size = SAMPLE_LIMIT)])
else:
    points = np.array(Points)

# compute Voronoi tesselation
vor = Voronoi(points)

# plot
voronoi_plot_2d(vor)

# colorize
for region in vor.regions:
    if not -1 in region:
        polygon = [vor.vertices[i] for i in region]
        plt.fill(*zip(*polygon))

plt.show()<commit_msg>feature: use pandas to load data and modified plot format<commit_after>import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d
import pandas

import os

COUNT_LIMIT = None
SAMPLE_LIMIT = 20

cell_info = pandas.read_csv('cell_info.csv', header=None, dtype={0: str, 1: float, 2:float}, nrows=COUNT_LIMIT)
cell_info.columns = ("name", "x", "y")

# 随机抽取
if SAMPLE_LIMIT:
    cells = np.array([(cell_info["x"][i], cell_info["y"][i]) for i in np.random.choice(len(cell_info), size = SAMPLE_LIMIT)])
else:
    cells = np.array(cell_info["x", "y"])

# compute Voronoi tesselation
vor = Voronoi(cells)

# plot
fig = voronoi_plot_2d(vor)
fig.canvas.set_window_title("基站服务范围示意图")
title = fig.suptitle("cell_info")
ax = fig.gca()
ax.set_aspect(1.)

# colorize
for region in vor.regions:
    if -1 not in region:
        polygon = [vor.vertices[i] for i in region]
        _ = ax.fill(*zip(*polygon)) # plt.fill((x0, x1, x2, x3, ...), (y0, y1, y2, y3, ...), color=None)

plt.show()
{'fraction_non_alphanumeric': 0.13551401869158877, 'fraction_numerical': 0.013499480789200415, 'mean_word_length': 4.084432717678101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1411061', 'n_tokens_mistral': 765, 'n_tokens_neox': 762, 'n_words': 190}