2D and 3D Scatter Histograms from arrays in Python

Here it follows two functions: hist2d_bubble and hist3d_bubble; that may fit for your purpose: import numpy as np import matplotlib.pyplot as pyplot from mpl_toolkits.mplot3d import Axes3D def hist2d_bubble(x_data, y_data, bins=10): ax = np.histogram2d(x_data, y_data, bins=bins) xs = ax[1] ys = ax[2] points = [] for (i, j), v in np.ndenumerate(ax[0]): points.append((xs[i], ys[j], v)) points = … Read more

Mapping ranges of values in pandas dataframe [duplicate]

There are a few alternatives. Pandas via pd.cut / NumPy via np.digitize You can construct a list of boundaries, then use specialist library functions. This is described in @EdChum’s solution, and also in this answer. NumPy via np.select df = pd.DataFrame(data=np.random.randint(1,10,10), columns=[‘a’]) criteria = [df[‘a’].between(1, 3), df[‘a’].between(4, 7), df[‘a’].between(8, 10)] values = [1, 2, 3] … Read more

Binning a column with pandas

You can use pandas.cut: bins = [0, 1, 5, 10, 25, 50, 100] df[‘binned’] = pd.cut(df[‘percentage’], bins) print (df) percentage binned 0 46.50 (25, 50] 1 44.20 (25, 50] 2 100.00 (50, 100] 3 42.12 (25, 50] bins = [0, 1, 5, 10, 25, 50, 100] labels = [1,2,3,4,5,6] df[‘binned’] = pd.cut(df[‘percentage’], bins=bins, labels=labels) print … Read more

Define and apply custom bins on a dataframe

Another cut answer that takes into account extrema: dat <- read.table(“clipboard”, header=TRUE) cuts <- apply(dat, 2, cut, c(-Inf,seq(0.5, 1, 0.1), Inf), labels=0:6) cuts[cuts==”6″] <- “0” cuts <- as.data.frame(cuts) cosinFcolor cosinEdge cosinTexture histoFcolor histoEdge histoTexture jaccard 1 3 0 0 1 1 0 0 2 0 0 5 0 2 2 0 3 1 0 2 … Read more

Histogram using gnuplot?

yes, and its quick and simple though very hidden: binwidth=5 bin(x,width)=width*floor(x/width) plot ‘datafile’ using (bin($1,binwidth)):(1.0) smooth freq with boxes check out help smooth freq to see why the above makes a histogram to deal with ranges just set the xrange variable.