2016-03-27 9 views
1

Ich versuche zu sehen, ob NaNS irgendwo konzentriert sind, oder ob es ein Muster für ihre Verteilung gibt. Die Idee ist es, Python zu verwenden, um eine heatMap der Matrix (200K Zeilen und 1k Spalten) zu zeichnen und eine spezielle Farbe für NaN Werte zu setzen (der Rest der Werte kann durch die gleiche Farbe dargestellt werden, dies ist nicht möglich) ‚t Angelegenheit)Heat Map für eine sehr große Matrix, einschließlich NaNs

ein Beispiel für eine mögliche Anzeige: A proposition for example

Vielen Dank im Voraus

+1

Ich denke, [missingno] (https: //github.com/ResidentMario/missingno) könnte einen Blick wert sein. Nicht sicher, ob es tun kann, was Sie brauchen, aber ... – swenzel

Antwort

0
# Learn about API authentication here: https://plot.ly/python/getting-started 
# Find your api_key here: https://plot.ly/settings/api 

import plotly.plotly as py 
import plotly.graph_objs as go 

data = [ 
    go.Heatmap(
     z=[[1, 20, 30], 
     [20, 1, 60], 
     [30, 60, 1]] 
    ) 
] 
plot_url = py.plot(data, filename='basic-heatm 

soruce: https://plot.ly/python/heatmaps/

+0

danke aber nein, ich kenne diese einfache Lösung bereits und möchte einen Weg, ein sehr großes Objekt (mit NaNs) zu plotten, wie in meinem Post – dark

0

Was könnten Sie tun, ist ein Streudiagramm verwendet werden: mit xrange statt Bereich für Speedup

import matplotlib.pyplot as plt 
import numpy as np 
# create a matrix with random numbers 
A = np.random.rand(2000,10) 
# make some NaNs in it: 
for _ in range(1000): 
    i = np.random.randint(0,2000) 
    j = np.random.randint(0,10) 
    A[i,j] = np.nan 
# get a matrix to plot with only the NaNs: 
B = np.isnan(A) 
# if NaN plot a point. 
for i in range(2000): 
    for j in range(10): 
     if B[i,j]: plt.scatter(i,j) 
plt.show() 

wenn Python 2.6 oder 2.7 betrachten.

enter image description here

Hinweis. es könnte schneller sein zu tun:

C = np.where(B) 
plt.scatter(C[0],C[1]) 
2

A 1: 200 Seitenverhältnis ziemlich schlecht ist und, da man in den Speicher Probleme laufen könnte, sollten Sie wahrscheinlich brechen in mehrere Nx1k Stücke.

aber sagen, dass hier ist meine Lösung (durch Ihr Beispiel Bild inspiriert):

from mpl_toolkits.axes_grid1 import AxesGrid 

# generate random matrix 
xDim = 2000 
yDim = 4000 
# number of nans 
nNans = xDim*yDim*.1 
rands = np.random.rand(yDim, xDim) 

# create a skewed distribution for the nans 
x = np.clip(np.random.gamma(2, yDim*.125, size=nNans).astype(np.int),0 ,yDim-1) 
y = np.random.randint(0,xDim,size=nNans) 
rands[x,y] = np.nan 

# find the nans: 
isNan = np.isnan(rands) 

fig = plt.figure() 

# make axesgrid so we can put a histogram-like plot next to the data 
grid = AxesGrid(fig, 111, nrows_ncols=(1, 2), axes_pad=0.05) 

# plot the data using binary colormap 
grid[0].imshow(isNan, cmap=cm.binary) 

# plot the histogram 
grid[1].plot(np.sum(isNan,axis=1), range(isNan.shape[0])) 

# set ticks and limits, so the figure looks nice 
grid[0].set_xticks([0,250,500,750,1000,1250,1500,1750]) 
grid[1].set_xticks([0,250,500,750]) 
grid[1].set_xlim([0,750]) 
grid.axes_llc.set_ylim([0, yDim]) 
plt.show() 

Hier ist, wie es aussieht:

Figure produced by the code

+0

erklärt, ich erkannte nur jetzt, wo diese Frage fast ein halbes Jahr alt ist ... nun, ich hoffe, die Antwort wird noch für jemanden nützlich sein: D – swenzel