# Questions tagged [bins]

64 questions

1

votes

1

answer

196

Views

### Setting binwidth with geom_histogram function gives a blank graph

I'm very new to R and have written the following code for a histogram using ggplot2:
library(ggplot2)
graph1

1

votes

1

answer

93

Views

### R bins are percentages of column length

I have a table of several columns, with values from 1 to 8. The columns have different lenghts so I have filled them with NAs at the end. I would like to transform each column of the data so I will get something like this for each column:
1 2 3 4 5 6 7 8
0-25 1 0 0 0 0 1 0 2
25-50...

1

votes

1

answer

226

Views

### different sized bins in matlab

In Matlab I have a vector Muen which I want to reduce in size by dividing it in to different length bins. The vector has a few values that need high accuracy bins and a lot of values that are roughly equal and could be collected into bins with size of up to a few hundred values.
I also need to know...

1

votes

1

answer

688

Views

### MatLab Rose color by bin size

my Problem is the following.
I want to do a rose plot with Matlab. (http://de.mathworks.com/help/matlab/ref/rose.html)
I have the following code:
f2=figure('visible','off');
h=rose(degtorad(angles(:,i)),40);
title(['Marker '], 'FontSize',20)
x=get(h,'Xdata');
y=get(h,'Ydata');
g=patch(x,y,[0.3 0.3 0...

1

votes

1

answer

225

Views

### makings a bins column with dates in python

In python i have data that looks like this with 500.000 rows :
TIME count
1-1-1900 10:41:00 1
3-1-1900 09:54:00 1
4-1-1900 15:45:00 1
5-1-1900 18:41:00 1
4-1-1900 15:45:00 ...

1

votes

2

answer

80

Views

### Create vector based on range of values

I would like to create a vector that contains values based on a value range in an other vector.
Example:
I have a vector
A = [-2 1 3 -1 5 6]
And would like to a vector of say 3 groups based on the value of the of vector A. Let the groups be
Group 1: Values in A =5
The results vector would then be
X...

1

votes

1

answer

63

Views

### How can I create 6 bins and count all values that fall in each bin?

I have a few correlation matrices. I want to see how many values fall in 6 bins as follows; bin 1: 0 to 0.1, 0.1 to 0.2, 0.2 to 0.3, 0.3 to 0.4, 0.4 to 0.5 and 0.5 to 1.
My matrix:
dput(head(x3,n=1))
structure('1 0.0118056267220191 0.0698430295769578 0.147675160526577 -0.240526687986192 -0.2405266...

1

votes

2

answer

169

Views

### python - divide world into bins

I am working on trying to put moving balls into appropriate bins. I like to think I'm on the right track but I've been stuck for awhile now.
I left code out that didn't seem relevant to my question but if those who answer need further details I can provide them. Basically, I have a world of 200 mov...

1

votes

2

answer

44

Views

### SQL Sort data into age bins based on date of birth and timestamp of datapoint

I'm new to sql, and stackoverflow, so please show me mercy. I have 3 tables (described below). I have searched a lot for this specific problem and have not found a solution. I'm a graduate student studying the behavior and psychology of kids as they develop over years. I do this by observing an indi...

1

votes

1

answer

0

Views

### How can 'arrange' command be used to generate a set of bins for histogram plot in R

While I try to plot histogram in R by defining a set of bins I get this error 'some 'x' not counted; maybe 'breaks' do not span range of 'x''.
I am following the information on the website 'http://msenux.redwoods.edu/math/R/hist.php' which states 'Use the arange command to produce this set of bins'...

1

votes

1

answer

623

Views

### R hist right/left clump binning

I have a data set of length 15,000 with real values from 0 to 100. My data set is HEAVILY skewed to the left. I'm trying to accomplish the following bins: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, >10. What i have done so far is created the following:
breakvector = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100)...

1

votes

1

answer

129

Views

### How to pass an array of histogram breaks to R.hist using RProvider in F#?

I am using RProvider with F# in VS2012. I would like to pass an array of custom histogram breaks (bin edges) to R.hist. Things are ok when I pass an integer number (see line that is commented out). Could you please help me? What is the correct way to handle function overloading in this case?
R docum...

1

votes

1

answer

913

Views

### Histograms in Pandas

Relatively new to python and pandas. I have a dataframe: df with say 2 columns (say, 0 and 1) and n rows. I'd like to plot the histograms of the two time series data represented in the two columns. I also need access to the exact counts in the histogram for each bin for later manipulations.
b_counts...

1

votes

1

answer

3k

Views

### Label histogram by bins matplotlib [duplicate]

This question already has an answer here:
Matplotlib - label each bin
2 answers
I have a histogram in which I want to label the x-axis by bins. The histogram is plotted as a log log graph, but the bins are very specific. The graph:
The bins:
bins = [0, 0.035, 0.07, 0.15, 0.5, 1, 3, 10, 40]
Is th...

1

votes

3

answer

2.2k

Views

### What package is to be installed in R for scatter plots with logarithmic binning?

I am trying to produce some high density scatter plots with R. What package should be installed for this? Or is there any other way to obtain the plots.

0

votes

0

answer

6

Views

### How to count non-zeroes values using binned_statistic

I need to efficiently process very large 1D arrays extracting some statistics per bin and I have found very useful the function binned_statistic from scipy.stats as it includes a 'statistic' argument that works quite efficiently.
I would like to perform a 'count' function but without considering zer...

1

votes

1

answer

354

Views

### Matplotlib Histogram: Green and Blue Bins

I'm using pyplot to make a histogram. Here is approximately what I'm doing:
import numpy as np
import pylab as pl
A = {my dataset as a dictionary: different numbers and their frequencies}
numbers = A.keys()
frequencies = A.values()
plot = np.transpose(np.array([[numbers,frequencies]])
n =
pl.hist(p...

1

votes

1

answer

254

Views

### MATLAB how to plot a vector of probability densities on to a histogram?

I currently have a vector of calculated probability densities, i.e.
probden = (0.0008, 0.0016, 0.0048, 0.0064, 0.0072, ... , 1.0936, ... , 0.0072, 0.0064, 0.0048, 0.0016, 0.0008)
The list of calculated probability densities should be in the shape of a normal distribution.
I also have a same length...

0

votes

1

answer

24

Views

### Split an array into data based on bins returned by numpy histogram

I have an array x with data like this: [3.1, 3.0, 3.3, 3.5, 3.8, 3.75, 4.0] etc.
I have another variable y with corresponding 0s and 1s [0, 1, 0]
I want to get from that new separate arrays to have that divided
freq, bins = np.histogram(X, 5)
That allows me to know the cutoffs for each bin. But how...

17

votes

2

answer

9.6k

Views

### Matplotlib histogram with collection bin for high values

I have an array with values, and I want to create a histogram of it. I am mainly interested in the low end numbers, and want to collect every number above 300 in one bin. This bin should have the same width as all other (equally wide) bins. How can I do this?
Note: this question is related to this q...

1

votes

3

answer

842

Views

### Divide into bins R

I have the following data
A 1 6
A 2 72
A 3 90
A 4 81
A 5 81
A 6 42
A 7 12
A 8 32
A 9 34
A 10 92
B 1 44
B 2 54
B 3 10
B 4 21
B 5 47
B 6 35
B 7 94
B 8 5
B 9 35
B 10 77
B 11 9
B 12 52
B 13 73
B 14 93
B 15 38
B...

6

votes

3

answer

11k

Views

### how to generate bins for histogram using apache math 3.0 in java?

I have been looking for away to generate bins for specific dataset (by specifying lower band, upper band and number of bins required) using apache common math 3.0. I have looked at Frequency http://commons.apache.org/math/apidocs/org/apache/commons/math3/stat/Frequency.html
but it does not give me w...

6

votes

5

answer

16.4k

Views

### Normalizing histogram bins in gnuplot

I'm trying to plot a histogram whose bins are normalized by the number of elements in the bin.
I'm using the following
binwidth=5
bin(x,width)=width*floor(x/width) + binwidth/2.0
plot 'file' using (bin($2, binwidth)):($4) smooth freq with boxes
to get a basic histogram, but I want the value of eac...

2

votes

3

answer

642

Views

### Find lists items closest to certain values in Python

I have a list of sorted floats y, as well as a list of unsorted floats x.
Now, I need to find out for every element in x between which values of y it lies, preferably by index of y. So for example, if
y=[1,2,3,4,5]
x[0]=3.5
I would need the output for index 0 of x to be (2,3), because 3.5 is betw...

3

votes

1

answer

15.5k

Views

### Python pyplot histogram: Adjusting bin width, Not number of bins

I have been able to make myself a pretty little histogram that looks like this:
I was able to produce the image with the following code:
import numpy as np
import matplotlib.pyplot as plt
plt.figure()
plt.axis([0, 6000, 0, 45000])
data['column'][data.value == 0].hist(bins=200, label='A')
data['...

1

votes

1

answer

2.9k

Views

### how to make a frequency function in matlab like the excel frequency function?

I have a list that is sorted and I want to know how many values are in each bin? I made bins using linspace(floor(fist_element_list), ceil(last_element_list), num_bins) Is there a built in function or an easy way to do this in Matlab? All I can think of is doing it manually. I would like a frequency...

4

votes

2

answer

713

Views

### cut several variables, using several different number of bins for each variable

I have a dataset which looks like this:
ID a b
ID1 0.1 20.3
ID2 0.2 21.6
ID3 1.2 1.5
etc.
I would like to group these values into equal-sized groups. This can be done with:
data$bin1

4

votes

2

answer

166

Views

### Pandas: Bin dates into 30 minute intervals and calculate averages

I have a Pandas dataframe with two columns which are speed and time.
speed date
54.72 1:33:56
49.37 1:33:59
37.03 1:34:03
24.02 7:39:58
28.02 7:40:01
24.04 7:40:04
24.02 7:40:07
25.35 7:40:10
26.69 7:40:13
32.04 7:40:16
28.02 11:05:43
30.71 11:05:46
29.36 11:05:49
18.68...

1

votes

1

answer

105

Views

### Create bins and dataframe including a calculation

import pandas as pd
import numpy as np
import random
import string
N = 100
J = [2012,2013,2014]
K = ['A','B','C','D','E','F','G','H']
L = ['h','d','a']
df = pd.DataFrame(
np.random.uniform(1,10,size=(N, 3)),
columns=list('XYZ')
)
df['ht'] = pd.Series(random.choice(K) for _ in range(N))
df['at'] =...

3

votes

1

answer

463

Views

### MATLAB: combining and normalizing histograms with different sample sizes

I have four sets of data, the distribution of which I would like to represent in MATLAB in one figure. Current code is:
[n1,x1]=hist([dataset1{:}]);
[n2,x2]=hist([dataset2{:}]);
[n3,x3]=hist([dataset3{:}]);
[n4,x4]=hist([dataset4{:}]);
bar(x1,n1,'hist');
hold on; h1=bar(x1,n1,'hist'); set(h1,'facec...

3

votes

1

answer

589

Views

### Unable to align bins in a histogram of datetime objects using the hist() function

So I am trying to plot a histogram of some datetime objects, but i can never get the bins to line up with the bars. My code is below:
I start by importing my stuff and declaring the start, end and a one day object:
import datetime
import matplotlib.pyplot as plt
end = datetime.date(2017,5,14)
star...

2

votes

1

answer

855

Views

### easy way to subset data into bins

I have a data frame as seen below with over 1000 rows. I would like to subset the data into bins by 1m intervals (0-1m, 1-2m, etc.). Is there an easy way to do this without finding the minimum depth and using the subset command multiple times to place the data into the appropriate bins?
Temp..ºC. D...

2

votes

2

answer

404

Views

### How to bin data based on values in one column, and count occurrences from another column excluding duplicates in R?

I have a file of r-values for correlations. I want to split the r-values into bins and count how many CNVs are in each bin. Is there a way to do this without the duplicates?
GeneChr SNP SNP_Position CNV start end r-value
1 rs7520551 100716167 1:101161140-10...

2

votes

1

answer

79

Views

### How do i get all the numbers of fft bins in a defined frequency band?

I use the matlab software. To my question.
I have a audio signal, on which i am applying a STFT. I take a segment
(46 ms, specifially chosen) out of my signal y(audio signal) and use a FFT on it. Then i go to the next segment, until to end of my audio signal.
My WAV-File is 10.8526 seconds long. I...

2

votes

1

answer

539

Views

### Equivalent of histc function in R?

Is there an equivalent function in R to the matlab function histc?
Vector and bins are numeric.
[ countInBin, binIndexOfVectorElement ] = histc( vector, bins )
where:
bins = min(vector) : increment : max( vector )
and
length( binIndexOfVectorElement ) = length( vector )

2

votes

1

answer

475

Views

### How to create a difference map between two matplotlib hexbin maps?

I encountered a problem on creating a difference map between two matplotlib.pyplot hexbin plots, which means to get the value differences of each corresponding hexbin first and then create a difference hexbin map.
To give a simple example of my problem here, say the value of one hexbin in Map 1 is...

2

votes

2

answer

230

Views

### histogram with varying bin widths

I am trying to replicate the concept of chart Fig 1 from the following paper (http://dx.doi.org/10.1016/j.envsci.2011.08.004):
It is a histogram whose bin widths vary dependent upon the value of x and whose height depends on variable y. The precise values in the chart are not of concern - rather, u...

3

votes

0

answer

1.1k

Views

### Numpy: binning data with ties according to percentiles

I want to bin my data into 10 bins (histograms) using percentile ranges:
bins = [0, 10th-percentile(myData), 20th-percentile(myData), 30th..., 90th-percentile(myData), +inf]
So in order make a histogram out of my data, I just do:
import numpy as np
myBinnedData = np.histogram(myData, bins=bins)[0]
M...

2

votes

2

answer

67

Views

### Python: checking which bins two time points belong to

I have a list of lists with two values that represent a start time-point and an end time-point. I would like to count how much of the time range between the two points fall into bins.
The bins are between 0-300,300-500 and 500-1200.
I would also like to bin them between 0-50, 50-100, 100-150 and so...

7

votes

1

answer

2.3k

Views

### With `pandas.cut()`, how do I get integer bins and avoid getting a negative lowest bound?

My dataframe has zero as the lowest value. I am trying to use the precision and include_lowest parameters of pandas.cut(), but I can't get the intervals consist of integers rather than floats with one decimal. I can also not get the left most interval to stop at zero.
import pandas as pd
import seab...