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
15
votes
4 answers

pandas histogram: plot histogram for each column as subplot of a big figure

I am using the following code, trying to plot the histogram of every column of a my pandas data frame df_in as subplot of a big figure. %matplotlib notebook from itertools import combinations import matplotlib.pyplot as plt fig, axes =…
Edamame
  • 23,718
  • 73
  • 186
  • 320
15
votes
2 answers

Pandas dataframe: ValueError: num must be 1 <= num <= 0, not 1

I am getting the following error while I am trying to plot a pandas dataframe: ValueError: num must be 1 <= num <= 0, not 1 Code: import matplotlib.pyplot as plt names = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety'] custom =…
KostasRim
  • 2,053
  • 1
  • 16
  • 32
15
votes
1 answer

How to generate a word frequency histogram, where bars are ordered according to their height

I have a long list of words, and I want to generate a histogram of the frequency of each word in my list. I was able to do that in the code below: import csv from collections import Counter import numpy as np word_list =…
BKS
  • 2,227
  • 4
  • 32
  • 53
15
votes
1 answer

How to make 3D histogram in R

This is my goal: Plot the frequency of y according to x in the z axis. These are my problems: I have a two columns array (x and y) and need to divide x into classes (p.ex. 0.2 ou 0.5) and calculate the frequency of y for each class of x. The plot…
José Ricardo
  • 301
  • 1
  • 2
  • 7
15
votes
1 answer

R Normalize then plot two histograms together in R

I realize there have been several posts for people asking how to plot two histograms together side by side (as in one plot with the bars next to each other) and overlaid in R and also on how to normalize data. Following the advice that I've found,…
Harry B
  • 351
  • 1
  • 5
  • 17
15
votes
4 answers

Fixing the Radial Axis on MATLAB Polar Plots

I'm using polar plots (POLAR(THETA,RHO)) in MATLAB. Is there an easy way to fix the range for the radial axis to say, 1.5? I'm looking for something analogous to the xlim, ylim commands for cartesian axes. Haven't found anything in the docs yet.
Adam Holmberg
  • 7,245
  • 3
  • 30
  • 53
15
votes
3 answers

Howto bin series of float values into histogram in Python?

I have set of value in float (always less than 0). Which I want to bin into histogram, i,e. each bar in histogram contain range of value [0,0.150) The data I have looks like this: 0.000 0.005 0.124 0.000 0.004 0.000 0.111 0.112 Whith my code below…
neversaint
  • 60,904
  • 137
  • 310
  • 477
15
votes
2 answers

Add a vertical line with different intercept for each panel in ggplot2

I'm using ggplot2 to create panels of histograms, and I'd like to be able to add a vertical line at the mean of each group. But geom_vline() uses the same intercept for each panel (i.e. the global mean): require("ggplot2") # setup some sample…
yoyoyoyosef
  • 7,000
  • 8
  • 40
  • 39
15
votes
4 answers

Gnuplot change color of bars in histogram

is it possible to change the color of bars in a Gnuplot script dynamically? I have the following script reset fontsize = 12 set term postscript enhanced eps fontsize set output "bargraph_speedup.eps" set style fill solid 1.00 border 0 set style…
Sven Hager
  • 3,144
  • 4
  • 24
  • 32
15
votes
2 answers

iOS GLSL. Is There A Way To Create An Image Histogram Using a GLSL Shader?

Elsewhere on StackOverflow a question was asked regarding a depthbuffer histogram - Create depth buffer histogram texture with GLSL. I am writing an iOS image-processing app and am intrigued by this question but unclear on the answer provided. So,…
dugla
  • 12,774
  • 26
  • 88
  • 136
14
votes
2 answers

Change histogram bar colours greater than a certain value

So far, I've managed to change the colour a single bar in a histogram following the example here test <- rnorm(100); h <- hist(test); b <- cut(1, h$breaks); clr <- rep("grey", length(h$counts)); clr[b] <- "red"; plot(h, col=clr); I want to be able…
MattLBeck
  • 5,701
  • 7
  • 40
  • 56
14
votes
2 answers

How to add a mean and median line to a Seaborn displot

Is there a way to add the mean and median to Seaborn's displot? penguins = sns.load_dataset("penguins") g = sns.displot( data=penguins, x='body_mass_g', col='species', facet_kws=dict(sharey=False, sharex=False) ) Based on Add mean…
a11
  • 3,122
  • 4
  • 27
  • 66
14
votes
2 answers

Plotting two histograms from a pandas DataFrame in one subplot using matplotlib

I have a pandas dataframe like the following: df = pd.DataFrame({ 'a_wood' : np.random.randn(100), 'a_grassland' : np.random.randn(100), 'a_settlement' : np.random.randn(100), 'b_wood' :…
Max2603
  • 403
  • 1
  • 6
  • 23
14
votes
1 answer

python matplotlib histogram specify different colours for different bars

I want to colour different bars in a histogram based on which bin they belong to. e.g. in the below example, I want the first 3 bars to be blue, the next 2 to be red, and the rest black (the actual bars and colour is determined by other parts of…
Esme_
  • 1,360
  • 3
  • 18
  • 30
14
votes
4 answers

Histogram with equal number of points in each bin

I have a sorted vector points with 100 points. I now want to create two histograms: the first histogram should have 10 bins having equal width. The second should also have 10 histograms, but not necessarily of equal width. In the second, I just want…
Apollo
  • 8,874
  • 32
  • 104
  • 192