histogram

Add legend to ggplot histogram with different types of aesthetics

谁都会走 提交于 2019-12-05 19:34:53
I want to add a legend to one of my plots, but I have different aesthetics and I never created a legend so I find it very difficult to determine how to build it. One of my aesthetics is a fill code, which I added manually as a vector. The other aesthetic is a vertical line that I added with geom_vline. From the graph below, there are three characteristics that I want to add to the legend: 1) The bars with color dark blue, 2) The bars with color light blue and 3) The vertical line. Does anyone have a suggestion for me on how to code this efficiently? #df df <- data.frame(Time_Diff <- runif(1000

Plot x-ticks in histogram matplotlib

一曲冷凌霜 提交于 2019-12-05 18:15:02
I would like to plot the corresponding x for a given name. by that I mean, for foo it has to plot [10,20,30] in the form of a histogram and all foo, bar, baz need to be in the same graph .(I don't require 3d :) ) import pylab as P name = ['foo', 'bar', 'baz'] x = [[10,20,30],[40,50,60],[70,80,90]] P.figure() P.hist(x, 10, histtype='bar', color=['crimson', 'burlywood', 'chartreuse'], label=['Crimson', 'Burlywood', 'Chartreuse']) P.show() Hope this helps you: from matplotlib import pyplot as plt import numpy as np names = ['foo', 'bar', 'baz'] x = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]

fit a function to a histogram created with frequency in gnuplot

末鹿安然 提交于 2019-12-05 17:48:12
Intro In gnuplot there's a solution to create histogram from file named hist.dat what likes 1 2 2 2 3 by using commands binwidth=1 set boxwidth binwidth bin(x,width)=width*floor(x/width) + binwidth/2.0 plot [0:5][0:*] "hist.dat" u (bin($1,binwidth)):(1.0) smooth freq with boxes that generates a histogram like this one from other SO page . Question How can I fit my function to this histogram? I defined a Gaussian function and initialized its values by f(x) = a*exp(-((x-m)/s)**2) a=3; m=2.5; s=1 and in the output the function follow the histogram well. Unfortunatelly I cannot fit to this

entropy estimation using histogram of normal data vs direct formula (matlab)

孤街浪徒 提交于 2019-12-05 17:20:21
Let's assume we have drawn n=10000 samples of the standard normal distribution. Now I want to calculate its entropy using histograms to calculate the probabilities. 1) calculate probabilities (for example using matlab) [p,x] = hist(samples,binnumbers); area = (x(2)-x(1))*sum(p); p = p/area; (binnumbers is determined due to some rule) 2) estimate entropy H = -sum(p.*log2(p)) which gives 58.6488 Now when i use the direct formula to calculate the entropy of normal data H = 0.5*log2(2*pi*exp(1)) = 2.0471 What do i do wrong when using the histograms + entropy formula? Thank you very much for any

cumulative histogram has last point at y=0

对着背影说爱祢 提交于 2019-12-05 16:49:04
问题 I am creating histogram with pylab.hist(data,weights,histtype='step',normed=False,bins=150,cumulative=True) getting (there are other plots, which are irrelevant now) the violet line Why is the histogram dropping to zero at the end again? Cumulative functions should be in general non-decreasing. Is there a way to work around this, be it bug or feature? EDIT: solution (hack): # histtype=step returns a single patch, open polygon n,bins,patches=pylab.hist(data,weights,histtype='step',cumulative

Drawing histogram of CGImage in Swift 3

拟墨画扇 提交于 2019-12-05 16:32:07
I have a problem with vImageHistogramCalculation_ARGB8888 method while trying to convert library from Swift 2 to Swift 3 version. The problem is that the method accepts "histogram" argument only as UnsafeMutablePointer<UnsafeMutablePointer<T>?> but Swift 3 construction let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(mutating: rgba) return unwrapped value, so I can't cast it to properly type. The compiler error is: : Cannot invoke initializer for type 'UnsafeMutablePointer?>' with an argument list of type '(mutating: [UnsafeMutablePointer])' Have you some ideas? I

Gnuplot columnstacked histogram - line/row count

筅森魡賤 提交于 2019-12-05 15:52:37
I have a data file with an undefined number of entries that looks like this: A B C D E.. 1 0 2 5 4 7 4 3 4 1 8 7 4 0 7 1 1 First row represents working time, than pause and so on in alternating fashion. To visualise this, I plot a columnstacked histograms from it by defining two linestyles with different colours and plotting it via: plot for [i=1:10] 'data.log' using i notitle But the problem is: I have to guess the max value of i. How can I get the number of columns the data file has? And when defining the alternating linestyles I need to estimate the max number of lines in order to overwrite

How to plot a histogram with unequal widths without computing it from raw data?

主宰稳场 提交于 2019-12-05 14:19:13
Matplotlib's hist says "Compute and draw the histogram of x". I'd like to make a plot without computing anything first. I have the bin widths (unequal), and the total amount in each bin, and I want to plot a frequency-quantity histogram. For instance, with the data cm Frequency 65-75 2 75-80 7 80-90 21 90-105 15 105-110 12 It should make a plot like this: http://www.gcsemathstutor.com/histograms.php where the area of the blocks represents the frequency in each class. Pablo Working on the same as David Zwicker: import numpy as np import matplotlib.pyplot as plt freqs = np.array([2, 7, 21, 15,

How to create histogram from grouped data

让人想犯罪 __ 提交于 2019-12-05 11:59:00
I'm trying to create histogram from grouped data in pandas. So far I was able to create standard line plot. But I can't figure out how to do the same to get histogram (bar chart). I would like to get 2 age histograms of persons who survived Titanic crush and who didn't - to see if there is a difference in age distribution. Source data: https://www.udacity.com/api/nodes/5454512672/supplemental_media/titanic-datacsv/download So far my code: import pandas as pn titanic = pn.DataFrame.from_csv('titanic_data.csv') SurvivedAge= titanic.groupby(['Survived','Age']).size() SurvivedAge=SurvivedAge.reset

How to histogram day-of-week, and have string labels

纵然是瞬间 提交于 2019-12-05 10:19:44
I have a data-frame of dates (Date object); see bottom. I'm trying to convert them to day-of-week and then draw a histogram, but ideally where the labels are 'Monday'...'Sunday' (not numeric) I have two distinct problems: It's easy to convert a Date object to day-of-week , but the result is string or numeric, not an object. When I get a histogram, the bins and labels are wrong (see below). If I use weekdays(dat) , the output is string ("Monday"...) which cannot be used in hist() . Alternatively, if I convert to numeric data, how to get string labels on hist() ? > dotw <- with( month.day.year