我有一组具有坐标(x,y)的一组点的文件,我使用三角测量方法生成表示曲面的三角形网。三角测量由一个由n个点和n个三角形组成的非结构化三角形网格组成。在Python中绘制密度图的三角测量方法
数据作图从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 /表面),然后绘制密度图。
绘制密度图BY三角测量法
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/
这里是原始图像: http://postimg.org/image/lqn1b8lmx/6dca1266/
Mraquel,您可以将您的密度地图上传到其他服务并在此处发布链接。 –
非常感谢@CristianoAraujo – Mraquel
你想在这张图中展示什么? –