3D discrete heatmap in matplotlib

New answer: It seems we really want to have a 3D Tetris game here 😉 So here is a way to plot cubes of different color to fill the space given by the arrays (x,y,z). from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt import matplotlib.cm import matplotlib.colorbar import matplotlib.colors def cuboid_data(center, … Read more

Custom Annotation Seaborn Heatmap

This feature has just been added in the recent version of Seaborn 0.7.1. From Seaborn update history: The annot parameter of heatmap() now accepts a rectangular dataset in addition to a boolean value. If a dataset is passed, its values will be used for the annotations, while the main dataset will be used for the … Read more

Conditional coloring of cells in table

A heatmap alternative: library(gplots) # need data as matrix mm <- as.matrix(testdf, ncol = 3) heatmap.2(x = mm, Rowv = FALSE, Colv = FALSE, dendrogram = “none”, cellnote = mm, notecol = “black”, notecex = 2, trace = “none”, key = FALSE, margins = c(7, 11)) In heatmap.2 the side of the plot the axis … Read more

Generate a heatmap using a scatter data set

If you don’t want hexagons, you can use numpy’s histogram2d function: import numpy as np import numpy.random import matplotlib.pyplot as plt # Generate some test data x = np.random.randn(8873) y = np.random.randn(8873) heatmap, xedges, yedges = np.histogram2d(x, y, bins=50) extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] plt.clf() plt.imshow(heatmap.T, extent=extent, origin=’lower’) plt.show() This makes a 50×50 heatmap. … Read more

Plotting a 2D heatmap

The imshow() function with parameters interpolation=’nearest’ and cmap=’hot’ should do what you want. Please review the interpolation parameter details, and see Interpolations for imshow and Image antialiasing. import matplotlib.pyplot as plt import numpy as np a = np.random.random((16, 16)) plt.imshow(a, cmap=’hot’, interpolation=’nearest’) plt.show()

Understanding `scale` in R

log simply takes the logarithm (base e, by default) of each element of the vector. scale, with default settings, will calculate the mean and standard deviation of the entire vector, then “scale” each element by those values by subtracting the mean and dividing by the sd. (If you use scale(x, scale=FALSE), it will only subtract … Read more