2014-05-08 19 views
3

我已经设置如下所示的数据:如何可视化高volumn 3个维数据

import numpy as np 
from pandas import DataFrame 
mypos = np.random.randint(10, size=(100, 2)) 
mydata = DataFrame(mypos, columns=['x', 'y']) 
myres = np.random.rand(100, 1) 
mydata['res'] = myres 

的RE变量是连续时,变量x和y是代表 位置(因此在很大程度上重复)的整数, res表示一对位置之间的相关性。

我想知道什么是可视化这个数据集的最佳方式? 已经考虑的可能方法:

  1. 散点图,其中res变量通过颜色梯度显示。
  2. 平行坐标图。

第一种方法是有问题的,当位置的数量得到大, 因为高值(这是我们关心的值)RE的变量将在 小点的海洋所淹没。

第二种方法可能是有希望的,但我在生产时遇到了麻烦。 我已经尝试了熊猫模块中的parallel_coordinates功能, 但它并不像我希望的那样工作。 (在这里看到这个问题: parallel coordinates plot for continous data in pandas

+1

这是否应该用“r”标记?似乎它更像是一个Python Q. – TARehman

+0

是的,但我不介意在R中执行它,只要它能完成工作。 – qed

+0

成对的六角地块? –

回答

1

我希望这有助于找到R的解决方案。祝你好运。

# you need this package for the colour palette 
library(RColorBrewer) 

# create the random data 
dd <- data.frame(
    x = round(runif(100, 0, 10), 0), 
    y = round(runif(100, 0, 10), 0), 
    res = runif(100) 
) 

# pick the number of colours (granularity of colour scale) 
nColors <- 100 

# create the colour pallete 
cols <-colorRampPalette(colors=c("white","blue"))(nColors) 

# get a zScale for the colours 
zScale <- seq(min(dd$res), max(dd$res), length.out = nColors) 

# function that returns the nearest colour given a value of res 
findNearestColour <- function(x) { 
    colorIndex <- which(abs(zScale - x) == min(abs(zScale - x))) 
    return(cols[colorIndex]) 
} 

# the first plot is the scatterplot 
### this has problems because points come out on top of eachother 
plot(y ~ x, dd, type = "n") 
for(i in 1:dim(dd)[1]){ 
    with(dd[i,], 
     points(y ~ x, col = findNearestColour(res), pch = 19) 
    ) 
} 

# this is your parallel coordinates plot (a little better) 
plot(1, 1, xlim = c(0, 1), ylim = c(min(dd$x, dd$y), max(dd$x, dd$y)), 
    type = "n", axes = F, ylab = "", xlab = "") 
for(i in 1:dim(dd)[1]){ 
    with(dd[i,], 
     segments(0, x, 1, y, col = findNearestColour(res)) 
    ) 
}