【发布时间】:2015-08-25 23:44:32
【问题描述】:
我有一个文件,其中包含一组点的坐标 (x,y),并且我正在使用三角测量方法来生成代表表面的三角形网络。 三角剖分由一个非结构化的三角形网格组成,该网格由 n 个点和 n 个三角形组成。
从 CSV 文件中绘制数据:
from matplotlib import pyplot as plt
from pandas import DataFrame
from matplotlib import style
df = DataFrame.from_csv('d:\Users\Raquel\Desktop/test.csv', header=0,
sep=';') # unpact values into x and y using pandas to load my csv file
style.use('ggplot')
我使用这个三角形网格能够计算密度(1/表面),然后绘制密度图。
用三角法绘制密度图
import numpy as np
from matplotlib.pyplot import (tripcolor, triplot, scatter,
show, title, savefig, colorbar)
from matplotlib.tri import Triangulation, TriAnalyzer
# Coordinates
x = df['x'].values
y = df['y'].values
# Triangulation
tri = Triangulation(x, y)
# Coordinates of the edges
ii1, ii2, ii3 = tri.triangles.T
x1 = x[ii1] ; y1 = y[ii1]
x2 = x[ii2] ; y2 = y[ii2]
x3 = x[ii3] ; y3 = y[ii3]
# Surfaces
surf = 0.5*np.abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))
# Density
dens = 1.0/(surf*3) # 3 points per triangle
# Plot
xd = (x1+x2+x3)*1.0/3.
yd = (y1+y2+y3)*1.0/3.
tripcolor(xd, yd, dens, cmap='cool')
colorbar()
title('Density Map')
savefig('density.png')
show()
地图不能很好地表示我的点的密度,我不知道如何改进它......代码有问题吗?
注意: 这是我的密度图的图像: http://postimg.org/image/3y1g90nwd/c8d2af55/
【问题讨论】:
-
Mraquel,您可以将密度图上传到其他服务并在此处发布链接。
-
非常感谢@CristianoAraujo
-
你想在这张图中显示什么?
-
我正在尝试显示热点的密度(原始图像的棕色点)@CristianoAraujo
-
您是否尝试将颜色映射应用于图像?也许它可以确定你需要什么
标签: python triangulation delaunay