Fitting a density curve to a histogram in R

If I understand your question correctly, then you probably want a density estimate along with the histogram: X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4)) hist(X, prob=TRUE) # prob=TRUE for probabilities not counts lines(density(X)) # add a density estimate with defaults lines(density(X, adjust=2), lty=”dotted”) # add another “smoother” density Edit a long while … Read more

save a pandas.Series histogram plot to file

Use the Figure.savefig() method, like so: ax = s.hist() # s is an instance of Series fig = ax.get_figure() fig.savefig(‘/path/to/figure.pdf’) It doesn’t have to end in pdf, there are many options. Check out the documentation. Alternatively, you can use the pyplot interface and just call the savefig as a function to save the most recently … Read more

Histogram Matplotlib

import matplotlib.pyplot as plt import numpy as np mu, sigma = 100, 15 x = mu + sigma * np.random.randn(10000) hist, bins = np.histogram(x, bins=50) width = 0.7 * (bins[1] – bins[0]) center = (bins[:-1] + bins[1:]) / 2 plt.bar(center, hist, align=’center’, width=width) plt.show() The object-oriented interface is also straightforward: fig, ax = plt.subplots() ax.bar(center, … Read more

How does numpy.histogram() work?

A bin is range that represents the width of a single bar of the histogram along the X-axis. You could also call this the interval. (Wikipedia defines them more formally as “disjoint categories”.) The Numpy histogram function doesn’t draw the histogram, but it computes the occurrences of input data that fall within each bin, which … Read more

Scatterplot with marginal histograms in ggplot2

This is not a completely responsive answer but it is very simple. It illustrates an alternate method to display marginal densities and also how to use alpha levels for graphical output that supports transparency: scatter <- qplot(x,y, data=xy) + scale_x_continuous(limits=c(min(x),max(x))) + scale_y_continuous(limits=c(min(y),max(y))) + geom_rug(col=rgb(.5,0,0,alpha=.2)) scatter

Bin size in Matplotlib (Histogram)

Actually, it’s quite easy: instead of the number of bins you can give a list with the bin boundaries. They can be unequally distributed, too: plt.hist(data, bins=[0, 10, 20, 30, 40, 50, 100]) If you just want them equally distributed, you can simply use range: plt.hist(data, bins=range(min(data), max(data) + binwidth, binwidth)) Added to original answer … Read more

Histogram using gnuplot?

yes, and its quick and simple though very hidden: binwidth=5 bin(x,width)=width*floor(x/width) plot ‘datafile’ using (bin($1,binwidth)):(1.0) smooth freq with boxes check out help smooth freq to see why the above makes a histogram to deal with ranges just set the xrange variable.

How to plot two histograms together in R?

Here is an even simpler solution using base graphics and alpha-blending (which does not work on all graphics devices): set.seed(42) p1 <- hist(rnorm(500,4)) # centered at 4 p2 <- hist(rnorm(500,6)) # centered at 6 plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10)) # first histogram plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T) # second The key is that the colours are … Read more