histogram

Exact number of bins in Histogram in R

落花浮王杯 提交于 2019-12-17 10:46:27
问题 I'm having trouble making a histogram in R. The problem is that I tell it to make 5 bins but it makes 4 and I tell to make 5 and it makes 8 of them. data <- c(5.28, 14.64, 37.25, 78.9, 44.92, 8.96, 19.22, 34.81, 33.89, 24.28, 6.5, 4.32, 2.77, 17.6, 33.26, 52.78, 5.98, 22.48, 20.11, 65.74, 35.73, 56.95, 30.61, 29.82); hist(data, nclass = 5,freq=FALSE,col="orange",main="Histogram",xlab="x",ylab="f(x)",yaxs="i",xaxs="i") Any ideas on how to fix it? 回答1: Use the breaks argument: hist(data, breaks

python histogram one-liner

徘徊边缘 提交于 2019-12-17 10:18:50
问题 There are many ways to write a Python program that computes a histogram. By histogram, I mean a function that counts the occurrence of objects in an iterable and outputs the counts in a dictionary. For example: >>> L = 'abracadabra' >>> histogram(L) {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r': 2} One way to write this function is: def histogram(L): d = {} for x in L: if x in d: d[x] += 1 else: d[x] = 1 return d Are there more concise ways of writing this function? If we had dictionary comprehensions

create heatmap2d from txt file

醉酒当歌 提交于 2019-12-17 09:54:36
问题 I have set of 2d data (30K) as txt file. X Y 2.50 135.89 2.50 135.06 2.50 110.85 2.50 140.92 2.50 157.53 2.50 114.61 2.50 119.53 2.50 154.14 2.50 136.48 2.51 176.85 2.51 147.19 2.51 115.59 2.51 144.57 2.51 148.34 2.51 136.73 2.51 118.89 2.51 145.73 2.51 131.43 2.51 118.17 2.51 149.68 2.51 132.33 I plotted as a scatter plot with gnuplot but I would like to represent as a heatmap2d or density distribution. I looked through the examples in MatPlotLib or R and they all seem to already start with

Extract data from a ggplot

那年仲夏 提交于 2019-12-17 09:19:10
问题 I have made a plot using ggplot2 geom_histogram from a data frame. See sample below and link to the ggplot histogram Need to label each geom_vline with the factors using a nested ddply function and facet wrap I now need to make a data frame that contains the summarized data used to generate the ggplot above. Sector2 Family Year Length BUN Acroporidae 2010 332.1300496 BUN Poritidae 2011 141.1467966 BUN Acroporidae 2012 127.479 BUN Acroporidae 2013 142.5940556 MUR Faviidae 2010 304.0405 MUR

2D and 3D Scatter Histograms from arrays in Python

对着背影说爱祢 提交于 2019-12-17 07:40:02
问题 have you any idea, how I can bin 3 arrays to a histogram. My arrays look like Temperature = [4, 3, 1, 4, 6, 7, 8, 3, 1] Radius = [0, 2, 3, 4, 0, 1, 2, 10, 7] Density = [1, 10, 2, 24, 7, 10, 21, 102, 203] And the 1D plot should look: Density | X 10^2-| X | X 10^1-| | X 10^0-| |___|___|___|___|___ Radius 0 3.3 6.6 10 And the 2D plot should (qualitative) look like: Density | 2 | | 10^2-| 11249 | | | 233 | | Radius 10^1-| 12 | | | 1 | | 10^0-| |___|___|___|___|___ Temperature 0 3 5 8 So I want to

2D and 3D Scatter Histograms from arrays in Python

六月ゝ 毕业季﹏ 提交于 2019-12-17 07:39:39
问题 have you any idea, how I can bin 3 arrays to a histogram. My arrays look like Temperature = [4, 3, 1, 4, 6, 7, 8, 3, 1] Radius = [0, 2, 3, 4, 0, 1, 2, 10, 7] Density = [1, 10, 2, 24, 7, 10, 21, 102, 203] And the 1D plot should look: Density | X 10^2-| X | X 10^1-| | X 10^0-| |___|___|___|___|___ Radius 0 3.3 6.6 10 And the 2D plot should (qualitative) look like: Density | 2 | | 10^2-| 11249 | | | 233 | | Radius 10^1-| 12 | | | 1 | | 10^0-| |___|___|___|___|___ Temperature 0 3 5 8 So I want to

fast 2dimensional histograming in matlab

不想你离开。 提交于 2019-12-17 07:32:25
问题 I have written a 2D histogram algorithm for 2 matlab vectors. Unfortunately, I cannot figure out how to vectorize it, and it is about an order of magnitude too slow for my needs. Here is what I have: function [ result ] = Hist2D( vec0, vec1 ) %Hist2D takes two vectors, and computes the two dimensional histogram % of those images. It assumes vectors are non-negative, and bins % are the integers. % % OUTPUTS % result - % size(result) = 1 + [max(vec0) max(vec1)] % result(i,j) = number of pixels

fast 2dimensional histograming in matlab

对着背影说爱祢 提交于 2019-12-17 07:32:06
问题 I have written a 2D histogram algorithm for 2 matlab vectors. Unfortunately, I cannot figure out how to vectorize it, and it is about an order of magnitude too slow for my needs. Here is what I have: function [ result ] = Hist2D( vec0, vec1 ) %Hist2D takes two vectors, and computes the two dimensional histogram % of those images. It assumes vectors are non-negative, and bins % are the integers. % % OUTPUTS % result - % size(result) = 1 + [max(vec0) max(vec1)] % result(i,j) = number of pixels

Logarithmic y-axis bins in python

一曲冷凌霜 提交于 2019-12-17 07:26:16
问题 I'm trying to create a histogram of a data column and plot it logarithmically ( y-axis ) and I'm not sure why the following code does not work: import numpy as np import matplotlib.pyplot as plt data = np.loadtxt('foo.bar') fig = plt.figure() ax = fig.add_subplot(111) plt.hist(data, bins=(23.0, 23.5,24.0,24.5,25.0,25.5,26.0,26.5,27.0,27.5,28.0)) ax.set_xlim(23.5, 28) ax.set_ylim(0, 30) ax.grid(True) plt.yscale('log') plt.show() I've also tried instead of plt.yscale('log') adding Log=true in

Logarithmic y-axis bins in python

自古美人都是妖i 提交于 2019-12-17 07:26:03
问题 I'm trying to create a histogram of a data column and plot it logarithmically ( y-axis ) and I'm not sure why the following code does not work: import numpy as np import matplotlib.pyplot as plt data = np.loadtxt('foo.bar') fig = plt.figure() ax = fig.add_subplot(111) plt.hist(data, bins=(23.0, 23.5,24.0,24.5,25.0,25.5,26.0,26.5,27.0,27.5,28.0)) ax.set_xlim(23.5, 28) ax.set_ylim(0, 30) ax.grid(True) plt.yscale('log') plt.show() I've also tried instead of plt.yscale('log') adding Log=true in