欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python获取坐标颜色,python – 根据一组坐标的数据着色地图

发布时间:2024/7/23 python 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python获取坐标颜色,python – 根据一组坐标的数据着色地图 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

您的第一种方法称为Voronoi diagramm

对于使用D3库的javascipt,这种图表有一个解决方案

为了使这个解决方案完整,我在这里粘贴M.Bostock示例中的代码

var w = 1280,

h = 800;

var projection = d3.geo.azimuthal()

.mode("equidistant")

.origin([-98, 38])

.scale(1400)

.translate([640, 360]);

var path = d3.geo.path()

.projection(projection);

var svg = d3.select("body").insert("svg:svg", "h2")

.attr("width", w)

.attr("height", h);

var states = svg.append("svg:g")

.attr("id", "states");

var cells = svg.append("svg:g")

.attr("id", "cells");

d3.json("us-states.json", function(collection) {

states.selectAll("path")

.data(collection.features)

.enter().append("svg:path")

.attr("d", path);

});

d3.csv("airports.csv", function(airports) {

var positions = [];

airports.forEach(function(airport) {

positions.push(projection([+airport.longitude, +airport.latitude]));

});

// Compute the Voronoi diagram of airports' projected positions.

var polygons = d3.geom.voronoi(positions);

var g = cells.selectAll("g")

.data(airports)

.enter().append("svg:g");

g.append("svg:path")

.attr("class", "cell")

.attr("d", function(d, i) { return "M" + polygons[i].join("L") + "Z"; })

.on("mouseover", function(d, i) {

d3.select("#footer span").text(d.name);

d3.select("#footer .hint").text(d.city + ", " + d.state);

});

g.append("svg:circle")

.attr("cx", function(d, i) { return positions[i][0]; })

.attr("cy", function(d, i) { return positions[i][1]; })

.attr("r", 1.5);

});

使用OpenGL和Gouraud着色可以轻松实现第二个解决方案,但是将它导出到SVG(或者除了位图之外的其他任何东西)并不容易.我会考虑任何替代方案.

总结

以上是生活随笔为你收集整理的python获取坐标颜色,python – 根据一组坐标的数据着色地图的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。