histogram

Is there a way to return same length arrays in numpy.hist?

不羁岁月 提交于 2019-12-24 00:06:37
问题 I'm trying to create a histogram plot in python, normalizing with some custom values the y-axis values. For this, I was thinking to do it like this: import numpy as np import matplotlib.pyplot as plt data = np.loadtxt('foo.bar') fig = plt.figure() ax = fig.add_subplot(111) hist=np.histogram(data, bins=(1.0, 1.5 ,2.0,2.5,3.0)) x=[hist[0]*5,hist[1]] ax.plot(x[0], x[1], 'o') but of course, the last line gives: ValueError: x and y must have same first dimension Is there a way to force np.hist to

combine histogram with scatter plot in R

感情迁移 提交于 2019-12-23 21:57:57
问题 I am trying to produce a plot with histogram and scatter plot in just one plot using a secondary axis. In detail, here is an example data: #generate example data set.seed(1) a <- rnorm(200,mean=500,sd=35) data <- data.frame(a = a, b = rnorm(200, mean=10, sd=2), c = c(rep(1,100), rep(0,100))) # produce a histogram of data$a hist(a, prob=TRUE, col="grey") #add a density line lines(density(a), col="blue", lwd=2) #scatter plot plot(data$a,data$b,col=ifelse(data$c==1,"red","black")) What I want to

Space between Y axis and bar on gnuplot histogram

丶灬走出姿态 提交于 2019-12-23 18:43:00
问题 I have gnuplot script like this: set term pos eps set style data histogram set style histogram clustered gap 1 set grid y set boxwidth 0.8 absolute set style fill transparent solid 0.8 noborder #set key outside right top vertical Left #component stuff set output 'eps/component.eps' set title "Component in interesting Issues" set xlabel "Components" set xtics nomirror rotate by -270 plot 'dat/!component' using 2:xtic(1) t "Count" lc rgbcolor "blue" lt 1 and data: Cmp count AM 167 NM 90 RM 83

Numpy histogram, how to take the maximum value in each bin

一曲冷凌霜 提交于 2019-12-23 17:07:03
问题 I have a series of numbers that I bin with the code above. Is it possible to return the maximum number in each bin? Have a look at the example code: from numpy import * a=array([1,4,5,6,7.8,9,3.4,5.,6,3.5,6,8,9,10]) bins=arange(0,11,1) h=hist(a,bins=bins) h=hist(a,bins=bins,weights=a) This is what it is return (array([ 0. , 1. , 0. , 6.9, 4. , 10. , 18. , 7.8, 8. , 28. ]), array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) I was wondering if it was possible to get 3.5 (which is the maximum number

Histogram of Array in Swift

◇◆丶佛笑我妖孽 提交于 2019-12-23 17:01:09
问题 I'm trying to write a generic histogram function that operates on an Array , but I'm running into difficulties as Type 'Element' does not conform to protocol 'Hashable' . extension Array { func histogram() -> [Array.Element: Int] { return self.reduce([Array.Element: Int]()) { (acc, key) in let value = (acc[key] == nil) ? 1 : (acc[key]! + 1) return acc.dictionaryByUpdatingKey(key: key, value: value) } } } where dictionaryByUpdatingKey(...) mutates an existing dictionary as follows: extension

Any way for matlab to sum an array according to specified bins NOT by for iteration? Best if there is buildin function for this

你离开我真会死。 提交于 2019-12-23 13:08:38
问题 For example, if A = [7,8,1,1,2,2,2]; % the bins (or subscripts) B = [2,1,1,1,1,1,2]; % the array then the desired function "binsum" has two outputs, one is the bins, and the other is the sum. It is just adding values in B according to subscripts in A. For example, for 2, the sum is 1 + 1 + 2 = 4, for 1 it is 1 + 1 = 2. [bins, sums] = binsum(A,B); bins = [1,2,7,8] sums = [2,4,2,1] The elements in "bins" need not be ordered but must correspond to elements in "sums". This can surely be done by

How to fit a curve to a histogram

痴心易碎 提交于 2019-12-23 12:46:48
问题 I've explored similar questions asked about this topic but I am having some trouble producing a nice curve on my histogram. I understand that some people may see this as a duplicate but I haven't found anything currently to help solve my problem. Although the data isn't visible here, here is some variables I am using just so you can see what they represent in the code below. Differences <- subset(Score_Differences, select = Difference, drop = T) m = mean(Differences) std = sqrt(var

Plotting Histogram with given x and y values

╄→尐↘猪︶ㄣ 提交于 2019-12-23 09:05:42
问题 I am trying to plot a histogram that lines up every x value with the y value on the plot. I have tried to use multiple resources, but unfortunately I wasn't able to find anything. This is the best way I could code to make a histogram. x = (1,2,3,4,5) y = (1,2,3,4,5) h=plt.hist(x,y) plt.axis([0, 6, 0, 6]) plt.show() I want a graph that looks like the image below without those a's on x-axis: 回答1: From your plot and initial code, I could gather that you already have the bin and the frequency

histogram without vertical lines

徘徊边缘 提交于 2019-12-23 08:51:21
问题 When I create a histogram, it looks a lot like this: set.seed(1) x <- 1:100 y <- x + rnorm(50) y=round(y) hist(y) Is there a way to make a histogram look a bit like this? I can only get a histogram with bins, which I don't need for my plot. I don't want the black bins, I actually only want the blue, green and red lines. Can stackoverflow point me in the right direction? 回答1: Put your histogram in an object, and use type="s" to get the stepwise plot : x <- rnorm(1000) y <- hist(x) plot(y

Simple R (histogram) from counted csv file [duplicate]

夙愿已清 提交于 2019-12-23 02:52:20
问题 This question already has answers here : Creating a histogram using aggregated data (4 answers) Closed 6 years ago . HI Guys I'm trying to plot a frequency graph of a simple 2d file file:data.csv terms,count 1,10 5,17 3,28 9,30 I want the first col(terms) to be the x-axis and the col(count) be the height/percentage. I've tried this: d<-read.csv(data.csv) hist(d) Error in hist.default(d) : 'x' must be numeric dc<-table(d) hist(dc) <-- wrong result. 回答1: The problem is that hist() needs a