histogram

How to plot a density estimate on top of the histogram? [duplicate]

风格不统一 提交于 2019-12-04 13:34:41
This question already has answers here : Closed 7 years ago . Possible Duplicate: Fitting a density curve to a histogram in R x is a NAs free numeric vector. I run: > hist(x,density(x), prob=TRUE) Error Message I get: Error in rank(x, ties.method = "min", na.last = "keep") : unimplemented type 'list' in 'greater' It was suggested that I set prob =TRUE when calling hist. If you can explain that as well, it will be great. Thank you. You need to call hist and density separately. Something like this: hist(x, prob=TRUE) lines(density(x)) 来源: https://stackoverflow.com/questions/12945951/how-to-plot

Matplotlib: How to convert a histogram to a discrete probability mass function?

人盡茶涼 提交于 2019-12-04 13:10:31
I have a question regarding the hist() function with matplotlib. I am writing a code to plot a histogram of data who's value varies from 0 to 1. For example: values = [0.21, 0.51, 0.41, 0.21, 0.81, 0.99] bins = np.arange(0, 1.1, 0.1) a, b, c = plt.hist(values, bins=bins, normed=0) plt.show() The code above generates a correct histogram (I could not post an image since I do not have enough reputation). In terms of frequencies, it looks like: [0 0 2 0 1 1 0 0 1 1] I would like to convert this output to a discrete probability mass function, i.e. for the above example, I would like to get a

How to plot a histogram with a custom distribution?

那年仲夏 提交于 2019-12-04 12:08:01
In an old statistics textbook, I found a table of a distribution of ages for a country's population: Percent of Age population ------------------ 0-5 8 5-14 18 14-18 8 18-21 5 21-25 6 25-35 12 35-45 11 45-55 11 55-65 9 65-75 6 75-85 4 I wanted to plot this distribution as a histogram in R, with the age ranges as breaks and the percent of population as the density, but there didn't seem to be a straightforward way to do it. R's hist() function wants you to supply the individual data points, not a pre-computed distribution such as this. Here's how I went about it. # Copy original textbook table

R - Shading part of a ggplot2 histogram

吃可爱长大的小学妹 提交于 2019-12-04 11:46:57
So I have this data: dataset = rbinom(1000, 16, 0.5) mean = mean(dataset) sd = sd(dataset) data_subset = subset(dataset, dataset >= (mean - 2*sd) & dataset <= (mean + 2*sd)) dataset = data.frame(X=dataset) data_subset = data.frame(X=data_subset) And here's how I'm drawing my histogram for dataset : ggplot(dataset, aes(x = X)) + geom_histogram(aes(y=..density..), binwidth=1, colour="black", fill="white") + theme_bw() How can I shade the data_subset portion of the histogram, like so? My solution is very similar to joran's -- I think they're both worth looking at for the slight differences:

GNUPLOT Each Histogram Bar with different color

可紊 提交于 2019-12-04 11:21:51
问题 I want to visualize the amount of different colors of a bitmap file. My Datasheet looks like: 1 163073164 4 185122087 3 255242000 8 255255255 3 000162232 1 181230029 1 127127127 1 136000021 3 200191231 I want to draw each color bar with its own color by using gnu plot histogram style. I just try something out by using "lc variable" but it doesnt work. :-( My GNUPLOT script by now: set style data histograms set boxwidth 1 set grid set style histogram cluster gap 0 set style fill solid 1.0

Set number of bins for histogram directly in ggplot

只愿长相守 提交于 2019-12-04 10:42:11
问题 I'd like to feed geom_histogram the number of bins for my histogram instead of controlling bins through binwidth . The documentation says I can do this by setting the bins argument. But when I run ggplot(data = iris, aes(x = Sepal.Length)) + stat_bin(bins = 5) I get an output message with 30 bins, as if I didn't specify binwidth at all. stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. I've tried feeding this argument to stat_bin and qplot with the same problem. Am

Creating a histogram with multiple data series using multhist in R

北慕城南 提交于 2019-12-04 10:42:06
I want to create a histogram with multiple data series on the same plot. The best method that I can find to do this is multhist() . I would like a plot in a style similar to hist() , and while ggplot() can also be used to perform this task, the graphics style is not what I want. Here is some example data: df <- structure(list(year = c(2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,

Can I plot several histograms in 3d?

白昼怎懂夜的黑 提交于 2019-12-04 10:10:19
I'd like to plot several histograms similar to the way these bar graphs are plotted. I've tried using the arrays returned by hist , but it seems that the bin edges are returned, so I can't use them in bar . Does anyone have any suggestions? If you use np.histogram to pre-compute the histogram, as you found you'll get the hist array and the bin edges . plt.bar expects the bin centres, so calculate them with: xs = (bins[:-1] + bins[1:])/2 To adapt the Matplotlib example: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add

Normalizing histogram bins in gnuplot

戏子无情 提交于 2019-12-04 09:38:28
问题 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 each bin to be divided by the size of the bin. How can I go about this in gnuplot, or using external tools if necessary? 回答1: In gnuplot 4.4, functions take on a different property, in that they can

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

牧云@^-^@ 提交于 2019-12-04 08:29:57
问题 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 np noise = np.random.normal(0,1,(1000,1)) (n,x,_) = plt.hist(noise, bins = np.linspace(-3,3,7), histtype=u'step' ) plt.plot(x[:-1],n) I need the line to correlate with each bin's count at the bin centers as if there was a histtype=u'line' flag to go