Questions tagged [bins]
235 questions
3
votes
1 answer
Python - Use bins from one sns.histplot() for another / Extract bin information from an sns.histpllot()
I am trying to plot 2 histograms side by side, the first one for the full dataset, and second one for a subset of the dataset. For comparability, I want both to have the same class intervals and the bin widths must be calculated as per the…

rahul-ahuja
- 1,166
- 1
- 12
- 24
3
votes
1 answer
How to draw a histogram with variable-width bins in Python?
Suppose I have data [1,2,3, 7,8,9,9, 20,30,40,100,1000] for which I want to draw a histogram with Python. All the bins I care about is [0,5], [5,10], and [10, +∞). How can I do it?
The following wouldn't do it, of course.
import matplotlib.pyplot as…

Paw in Data
- 1,262
- 2
- 14
- 32
3
votes
1 answer
Plotly: How to customize different bin widths for a plotly histogram?
I am trying to display an histogram with bins that have a different/customizable width. It seems that Plotly only allows to have a uniform bin width with xbins = dict(start , end, size).
For example, I would like for a set of data with integers…

Adrien
- 433
- 1
- 3
- 13
3
votes
1 answer
Pandas splitting rows by certain cumsum
Is there a way to split certain dataframe row so that I can make a group of rows with certain cumsum? In this example I want to split rows that makes cumsum 20
my data
timestamp counts cumsum
'2015-01-01 03:45:14' 4 4 …

junglekim
- 29
- 5
3
votes
1 answer
How to write pandas dataframe containing bins to a file so it can be read back into pandas?
I have a pandas dataframe in the following format:
df = pd.DataFrame({'a' : [0,1,2,3,4,5,6], 'b' : [-0.5, 0.0, 1.0, 1.2, 1.4, 1.3, 1.1]})
df['aBins'] = pd.cut(df['a'], bins = np.arange(0,10,2), include_lowest = True)
Where the each bin is…

mikedennis2
- 33
- 3
3
votes
2 answers
How to select a specific category of bins in python?
I have a list of numbers which I separated into bins using pandas.cut(). How can I select one category of the bins?
manhattanBedrmsPrice.head()
0 859
5 1055
9 615
11 663
13 1317
Name: Price Value, dtype: int64
bins =…

Diego
- 386
- 4
- 19
3
votes
2 answers
How to print categories in pandas.cut?
Notice that when you input pandas.cut into a dataframe, you get the bins of each element, Name:, Length:, dtype:, and Categories in the output. I just want the Categories array printed for me so I can obtain just the range of the number of bins I…

Phoebe
- 57
- 1
- 6
3
votes
1 answer
pandas: plot mean values within bins - formatting help needed
I am doing some solar system dynamics simulations, and have been using this project as an excuse to teach myself some python/pandas. The resulting data set has a little over 1000 records, with values for orbital inclination, eccentricity and so on…

Glenn Becker
- 33
- 1
- 4
3
votes
1 answer
Plotting intervals with barplot function R
I am using the solution in this question to try to plot a bar plot with specified intervals:
Create categorical variable in R based on range
I created my intervals and tried to use them in the barplot function but I am obviously missing a step…

nchimato
- 443
- 4
- 8
- 18
3
votes
1 answer
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…

geosciz
- 161
- 1
- 4
- 11
3
votes
1 answer
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:
…

mt88
- 2,855
- 8
- 24
- 42
3
votes
3 answers
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…

frixhax
- 1,325
- 3
- 18
- 30
3
votes
0 answers
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…

Ricky Robinson
- 21,798
- 42
- 129
- 185
2
votes
2 answers
Dividing a range into bins in matlab
I have the following range from a much larger matrix :
range(a)
ans =
94 153 144 59 79 90 131 64
My professor is asking us to: Divide the range into N = 10 equal-length segments (hereafter called “bins”), and for each bin, find…

patrick.belon
- 65
- 2
- 3
- 7
2
votes
1 answer
Histogram with equal area bins in ggplot2
I would like to create a histogram in ggplot2 where each bin has the same number of points and all bins have the same area. In base R we could do the following:
set.seed(123)
x <- rnorm(100)
hist(x, breaks = quantile(x, 0:10 / 10))
When I try this…

Quinten
- 35,235
- 5
- 20
- 53