histogram

Plot a histogram from a Dictionary

一笑奈何 提交于 2019-11-28 05:53:38
I created a dictionary that counts the occurrences in a list of every key and I would now like to plot the histogram of its content. This is the content of the dictionary I want to plot: {1: 27, 34: 1, 3: 72, 4: 62, 5: 33, 6: 36, 7: 20, 8: 12, 9: 9, 10: 6, 11: 5, 12: 8, 2: 74, 14: 4, 15: 3, 16: 1, 17: 1, 18: 1, 19: 1, 21: 1, 27: 2} So far I wrote this: import numpy as np import matplotlib.pyplot as plt pos = np.arange(len(myDictionary.keys())) width = 1.0 # gives histogram aspect to the bar diagram ax = plt.axes() ax.set_xticks(pos + (width / 2)) ax.set_xticklabels(myDictionary.keys()) plt.bar

Creating a histogram using aggregated data

元气小坏坏 提交于 2019-11-28 05:08:48
问题 Embarrassingly simple question... I'm new to R and I can't seem to wrap my head around this for some reason. I have a CSV file which looks something like this: Bin,Number 1363,5 1028,4 1303,3 1467,1 1242,3 1415,5 .. . The bin size is 1, with a range of 1000-1500. I have read my CSV file in, everything seems to be ok there, but I just cannot produce a simple histogram. I have tried simply using a barplot, but the data is not numerically ordered, so will not produce the output I need. Using

How to get the cumulative distribution function with NumPy?

折月煮酒 提交于 2019-11-28 04:58:50
I want to create a CDF with NumPy, my code is the next: histo = np.zeros(4096, dtype = np.int32) for x in range(0, width): for y in range(0, height): histo[data[x][y]] += 1 q = 0 cdf = list() for i in histo: q = q + i cdf.append(q) I am walking by the array but take a long time the program execution. There is a built function with this feature, isn't? I'm not really sure what your code is doing, but if you have hist and bin_edges arrays returned by numpy.histogram you can use numpy.cumsum to generate a cumulative sum of the histogram contents. >>> import numpy as np >>> hist, bin_edges = np

Combination Boxplot and Histogram using ggplot2

柔情痞子 提交于 2019-11-28 04:33:46
I am trying to combine a histogram and boxplot for visualizing a continuous variable. Here is the code I have so far require(ggplot2) require(gridExtra) p1 = qplot(x = 1, y = mpg, data = mtcars, xlab = "", geom = 'boxplot') + coord_flip() p2 = qplot(x = mpg, data = mtcars, geom = 'histogram') grid.arrange(p2, p1, widths = c(1, 2)) It looks fine except for the alignment of the x axes. Can anyone tell me how I can align them? Alternately, if someone has a better way of making this graph using ggplot2 , that would be appreciated as well. kohske you can do that by coord_cartesian() and align.plots

How to create a histogram

蹲街弑〆低调 提交于 2019-11-28 04:05:44
问题 I want to create a histogram within a C# program that uses EMGU. EMGU contains a class called MCvHistogram in it, but I don't know how to use it. 回答1: You should use DenseHistogram class if you want to use EmguCV. I'll show you basic usage: // Create a grayscale image Image<Gray, Byte> img = new Image<Gray, byte>(400, 400); // Fill image with random values img.SetRandUniform(new MCvScalar(), new MCvScalar(255)); // Create and initialize histogram DenseHistogram hist = new DenseHistogram(256,

Histogram matching of two images in Python 2.x?

橙三吉。 提交于 2019-11-28 04:01:16
I'm trying to match the histograms of two images (in MATLAB this could be done using imhistmatch ). Is there an equivalent function available from a standard Python library? I've looked at OpenCV, scipy, and numpy but don't see any similar functionality. ali_m I previously wrote an answer here explaining how to do piecewise linear interpolation on an image histogram in order to enforce particular ratios of highlights/midtones/shadows. The same basic principles underlie histogram matching between two images. Essentially you compute the cumulative histograms for your source and template images,

Normalizing y-axis in histograms in R ggplot to proportion by group

一笑奈何 提交于 2019-11-28 03:57:57
My question is very similar to Normalizing y-axis in histograms in R ggplot to proportion , except that I have two groups of data of different size, and I would like that each proportion is relative to its group size instead of the total size. To make it clearer, let's say I have two sets of data in a data frame: dataA<-rnorm(100,3,sd=2) dataB<-rnorm(400,5,sd=3) all<-data.frame(dataset=c(rep('A',length(dataA)),rep('B',length(dataB))),value=c(dataA,dataB)) I can plot the two distributions together with: ggplot(all,aes(x=value,fill=dataset))+geom_histogram(alpha=0.5,position='identity',binwidth

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

北城余情 提交于 2019-11-28 03:43:12
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 pictures of SAS histograms that do basically what I'm trying to do (but the site doesn't seem to have R versions): http://www.ats.ucla.edu/stat/sas/faq/histogram_anno.htm If possible, it would also be nice to have the flexibility to put the labels above or somewhere inside the bars, as desired. I'm trying to do this with the base R plotting facilities,

How to apply histogram on dependent data in R?

混江龙づ霸主 提交于 2019-11-28 02:23:13
问题 I want to visualise the proportional data (Nij/n) about the sinus (independent) and arr/AHB (dependent variable) cases in females and males by R. ggplot2 approach and any other is welcome! Pseudocode histogram of the second and third columns for the groups N11.1, ..., N32.1 Code N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1 Sinus 1.0 0.0 0.0 0.0 0.0 0.0 12.0 Arr/AHB 1.0 0.0 0.0 0.1 0.0 0.0 20.9 N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1 Sinus 1.0 0.0 0.0 0.0 0.0 0.0 4.0 Arr/AHB 1.0 0.0 0.0 0.0 0.0

Setting histogram breaks in JFreeChart

只愿长相守 提交于 2019-11-28 02:06:16
I am using JFreeChart to draw histograms by filling a HistogramDataset object with my data and using the ChartFactory.createHistogram(). However, So far I have not been able to find anything in the documentation on how to set the breaks of the histogram. Am I missing anything, or does JFreeChart nog offer this functionality? To illustrate what I mean with breaks, see the following two histograms generated from the same data with identical number of bins, but with different breaks. Note how the shapes of the distribution are very different between the two histograms, therefore it is important