Questions tagged [histogram]

In statistics, a histogram is a graphical representation, showing a visual impression of the distribution of data.

In statistics, a histogram is a graphical representation, showing a visual impression of the distribution of data. It is an estimate of the probability distribution of a continuous variable and was first introduced by Karl Pearson. A histogram consists of tabular frequencies, shown as adjacent rectangles, erected over discrete intervals (bins), with an area equal to the of the observations in the interval. The height of a rectangle is also equal to the frequency density of the interval, i.e., the frequency divided by the width of the interval. The total area of the histogram is equal to the number of data. A histogram may also be normalized displaying relative frequencies. It then shows the proportion of cases that fall into each of several categories, with the total area equaling 1. The categories are usually specified as consecutive, non-overlapping intervals of a variable. The categories (intervals) must be adjacent, and often are chosen to be of the same size.

Histograms are used to plot density of data, and often for density estimation: estimating the probability density function of the underlying variable. The total area of a histogram used for probability density is always normalized to 1. If the length of the intervals on the x-axis are all 1, then a histogram is identical to a relative frequency plot.

In scientific software for statistical computing and graphics, The function hist generates a histogram. It can also optionally scale it so that its total area is 1. This puts it in the right scale if one want to overlay a probability density curve.

More about it here : histogram wiki

6663 questions
32
votes
9 answers

Generating a histogram from column values in a database

Let's say I have a database column 'grade' like this: |grade| | 1| | 2| | 1| | 3| | 4| | 5| Is there a non-trivial way in SQL to generate a histogram like this? |2,1,1,1,1,0| where 2 means the grade 1 occurs twice, the 1s mean…
Thorsten79
  • 10,038
  • 6
  • 38
  • 54
32
votes
3 answers

matplotlib histogram: how to display the count over the bar?

With matplotlib's hist function, how can one make it display the count for each bin over the bar? For example, import matplotlib.pyplot as plt data = [ ... ] # some data plt.hist(data, bins=10) How can we make the count in each bin display over its…
xuhdev
  • 8,018
  • 2
  • 41
  • 69
32
votes
3 answers

Histogram equalization not working on color image - OpenCV

I am trying to perform a histogram equalization using OpenCV using the following function Mat Histogram::Equalization(const Mat& inputImage) { if(inputImage.channels() >= 3) { vector channels; …
user349026
31
votes
2 answers

How to change the figure size of Dataframe.hist for pandas 0.11.0

I am trying to make histograms for a dataframe with pandas 0.11.0 but the figure size is too small. How to change it? In pandas 0.19.0, hist has the figsize parameter.
AbhiGupta
  • 474
  • 1
  • 6
  • 14
31
votes
5 answers

Plot a histogram such that the total height equals 1

This is a follow-up question to this answer. I'm trying to plot normed histogram, but instead of getting 1 as maximum value on y axis, I'm getting different numbers. For array k=(1,4,3,1) import numpy as np def plotGraph(): import…
user40
  • 1,361
  • 5
  • 19
  • 34
30
votes
2 answers

Plotting probability density function by sample with matplotlib

I want to plot an approximation of probability density function based on a sample that I have; The curve that mimics the histogram behaviour. I can have samples as big as I want.
Cupitor
  • 11,007
  • 19
  • 65
  • 91
29
votes
3 answers

Cannot get histogram to show separated bins with vertical lines

Annoying strange problem and I have not been able to find a solution on this site yet (although the question has popped up) I am trying to make a histogram where the bins have the 'bar style' where vertical lines separate each bin but no matter what…
Canuck
  • 567
  • 1
  • 7
  • 15
29
votes
3 answers

Is there a clean way to generate a line histogram chart in Python?

I need to create a histogram that plots a line and not a step or bar chart. I am using python 2.7 The plt.hist function below plots a stepped line and the bins don't line up in the plt.plot function. import matplotlib.pyplot as plt import numpy as…
DanGoodrick
  • 2,818
  • 6
  • 28
  • 52
29
votes
2 answers

Spacing between bars in matplotlib hist() with thousands of bins

I'm making histograms using matplotlib's hist() function or bar(), and I want to use >10,000 bins (one bin to represent the counts at each coordinate of a large entity). Is there any way to create more whitespace between the vertical bars when I…
whymca
  • 291
  • 1
  • 3
  • 3
29
votes
2 answers

Getting information for bins in matplotlib histogram function

I am plotting a histogram in python using matplotlib by: plt.hist(nparray, bins=10, label='hist') Is it possible to print a dataframe that has the information for all the bins, like number of elements in every bin?
dreamer_999
  • 1,465
  • 3
  • 17
  • 22
29
votes
3 answers

Create range bins from SQL Server table for histograms

I have the following table in SQL Server: ----------------------------- ID Age Gender 1 30 F 2 35 M 3 32 M 4 18 F 5 21 F What I need to do…
user10901
  • 629
  • 1
  • 8
  • 16
28
votes
2 answers

How to label histogram bars with data values or percents in R

I'd like to label each bar of a histogram with either the number of counts in that bin or the percent of total counts that are in that bin. I'm sure there must be a way to do this, but I haven't been able to find it. This page has a couple of…
eipi10
  • 91,525
  • 24
  • 209
  • 285
28
votes
3 answers

Can't draw Histogram, 'x' must be numeric

I have a data file with this format: Weight Industry Type 251,787 Kellogg h 253,9601 Kellogg a 256,0758 Kellogg h .... I read the data and try to draw an histogram with this commands: ce <- read.table("file.txt", header = TRUE) …
José Joel.
  • 2,040
  • 6
  • 28
  • 46
28
votes
6 answers

python plot simple histogram given binned data

I have count data (a 100 of them), each correspond to a bin (0 to 99). I need to plot these data as histogram. However, histogram count those data and does not plot correctly because my data is already binned. import random import matplotlib.pyplot…
Curious
  • 3,507
  • 8
  • 28
  • 30
28
votes
4 answers

Fit a gaussian function

I have a histogram (see below) and I am trying to find the mean and standard deviation along with code which fits a curve to my histogram. I think there is something in SciPy or matplotlib that can help, but every example I've tried doesn't work. …
user1496646