histogram

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

依然范特西╮ 提交于 2019-12-06 07:38:08
问题 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

Number of peaks in histogram

断了今生、忘了曾经 提交于 2019-12-06 06:20:28
问题 I have 1D data that represent some intensity values. I want to detect number of components in these data (clusters of points with similar intensity, or alternatively number of "peaks" in histogram created from this data). This approach: 1D multiple peak detection? is not very useful for me, because one "peak" can contain more local maximums (see image below). Of cause, I can use statistical approach, for example, I can try to fit data for 1,2,3,....n peaks, then calculate BIC, AIC or whatever

Histogram with separate list denoting frequency

时光总嘲笑我的痴心妄想 提交于 2019-12-06 06:12:40
Suppose I have two lists: x1 = [1,2,3,4,5,6,7,8,1,10] x2 = [2,4,2,1,1,1,1,1,2,1] Here, each index i of the list is a point in time, and x2[i] denotes the number of times (frequency) than x1[i] was observed was observed at time i . Note also that x1[0] = 1 and x1[8] = 1, with a total frequency of 4 (= x2[0] + x2[8]). How do I efficiently turn this into a histogram? The easy way is below, but this is probably inefficient (creating third object and looping) and would hurt me since I have gigantic data. import numpy as np import matplotlib.pyplot as plt x3 = [] for i in range(10): for j in range

how to use compareHist function opencv

青春壹個敷衍的年華 提交于 2019-12-06 06:02:34
问题 img = cv2.imread('mandrill.png') histg = cv2.calcHist([img],[0],None,[256],[0,256]) if len (sys.argv) < 2: print >>sys.stderr, "Usage:", sys.argv[0], "<image>..." sys.exit (1) for fn in sys.argv[1:]: im = cv2.imread (fn) histr = cv2.calcHist([im],[0],None,[256],[0,256]) a = cv2.compareHist(histr,histg,cv2.cv.CV_COMP_CORREL) print a I am trying to use the code above to compare the correlation between histograms histr and histg when I run the code the I get the error 'module' object has no

using histogram to determine colored object presence?

久未见 提交于 2019-12-06 05:43:14
I'm trying to determine if portion of the picture contains red-white striped object (liftramp). If it is present, it looks like this: , and when not like this: The naive approach was to extract histogram, and count if there is more red pixels than blue/green ones: use Image::Magick; my $image = Image::Magick->new; my $rv = $image->Read($picture); #$rv = $image->Crop(geometry=>'26x100+484+40'); my @hist_data = $image->Histogram; my @hist_entries; # Histogram returns data as a single list, but the list is actually groups of 5 elements. Turn it into a list of useful hashes. while (@hist_data) {

Can I plot several histograms in 3d?

落爺英雄遲暮 提交于 2019-12-06 05:32:52
问题 I'd like to plot several histograms similar to the way thesebar 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? 回答1: 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

How to plot a realtime graph (histogram) using data obtained in a text file

◇◆丶佛笑我妖孽 提交于 2019-12-06 04:34:11
I have a continuously generated data (text file) generated by a program on the server. I want to plot the data as a real-time graph just like powergrid does. This was my approach: As the data is generated continuously on the server in a text file, I wrote a PHP script which reads that file( get_file_contents ), outputs the data points and plot the graph using sparkline jQuery plugin. But the problem is that it reads the file all at once . Moreover, the text file keeps on growing. Can anyone suggest me a better approach? As you're talking about using a Javascript plotting solution you do the

R - faster alternative to hist(XX, plot=FALSE)$count

时光总嘲笑我的痴心妄想 提交于 2019-12-06 03:46:47
I am on the lookout for a faster alternative to R's hist(x, breaks=XXX, plot=FALSE)$count function as I don't need any of the other output that is produced (as I want to use it in an sapply call, requiring 1 million iterations in which this function would be called), e.g. x = runif(100000000, 2.5, 2.6) bincounts = hist(x, breaks=seq(0,3,length.out=100), plot=FALSE)$count Any thoughts? A first attempt using table and cut : table(cut(x, breaks=seq(0,3,length.out=100))) It avoids the extra output, but takes about 34 seconds on my computer: system.time(table(cut(x, breaks=seq(0,3,length.out=100)))

matplotlib: How can you specify colour levels in a 2D historgram

不羁岁月 提交于 2019-12-06 03:23:11
问题 I would like to plot a 2D histogram that includes both positive and negative numbers. I have the following code which uses pcolormesh but I am unable to specify the color levels to force the white color to corresponds to zero (i.e., I want my colorbar to be symmetric around zero). I've also tried imshow. I know you can specify colour levels in plt.contour and plt.contourf but I can't find a way to plot the 2D histogram using blocks. Any advice would be greatly appreciated. import numpy as np

Octave: Creating Two Histograms with Color Blending

落花浮王杯 提交于 2019-12-06 02:41:03
问题 I am creating one histogram on top of another in Octave. hold on; hist(normalData(:, column), 10, 1, "facecolor", "g"); hist(anomalousData(:, column), 10, 1, "facecolor", "r"); hold off; As you can see there is overlap and the red data obscures some of the green data. Is there a way around this? Perhaps by having the colors blend on the overlapping portions? 回答1: There is a long way around your problem. Unfortunately the plotting property for transparency "facealpha" does not work with the