histogram

Logarithmic y-axis bins in python

一世执手 提交于 2019-11-27 04:21:39
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 the plt.hist line and also I tried ax.set_yscale('log') , but nothing seems to work. I either get an

Animation of histograms in subplot

落爺英雄遲暮 提交于 2019-11-27 03:49:48
问题 I have the following animated subplots that simulate histograms of four different distributions: import numpy from matplotlib.pylab import * import matplotlib.animation as animation n = 100 # generate 4 random variables from the random, gamma, exponential, and uniform distributions x1 = np.random.normal(-2.5, 1, 10000) x2 = np.random.gamma(2, 1.5, 10000) x3 = np.random.exponential(2, 10000)+7 x4 = np.random.uniform(14,20, 10000) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) def

Using Counter() in Python to build histogram?

与世无争的帅哥 提交于 2019-11-27 03:42:48
I saw on another question that I could use Counter() to count the number of occurrences in a set of strings. So if I have ['A','B','A','C','A','A'] I get Counter({'A':3,'B':1,'C':1}) . But now, how can I use that information to build a histogram for example? For your data it is probably better to use a barchart instead of a histogram. Check out this code: from collections import Counter import numpy as np import matplotlib.pyplot as plt labels, values = zip(*Counter(['A','B','A','C','A','A']).items()) indexes = np.arange(len(labels)) width = 1 plt.bar(indexes, values, width) plt.xticks(indexes

Fit a gaussian function

坚强是说给别人听的谎言 提交于 2019-11-27 03:41:20
I have a histogram (see below) and I am trying to find the mean and standard deviation along with code which fits a curve to my histogram. I think there is something in SciPy or matplotlib that can help, but every example I've tried doesn't work. import matplotlib.pyplot as plt import numpy as np with open('gau_b_g_s.csv') as f: v = np.loadtxt(f, delimiter= ',', dtype="float", skiprows=1, usecols=None) fig, ax = plt.subplots() plt.hist(v, bins=500, color='#7F38EC', histtype='step') plt.title("Gaussian") plt.axis([-1, 2, 0, 20000]) plt.show() Chris Take a look at this answer for fitting

How to plot multiple stacked histograms together in R?

别等时光非礼了梦想. 提交于 2019-11-27 03:35:53
问题 I am very very new to R (just started using it today), and I am trying to plot multiple histograms on top of each other. Ive come across a few posts that talk about how to plot two histograms on top of each other, but haven't found any that explain how to do multiple. Specifically for my example, 5. I have 5 values that I would like to plot stacked histograms of. a <- c(15.625,12.5,14,15.75,15.375,18.813) cs <- c(15.875, 7.875, 6.625, 6, 6.5, 9, 7.375, 7.625, 6.875, 7.25, 7.5, 6.75, 6.75, 7.5

How can I create a histogram from aggregated data in R?

不想你离开。 提交于 2019-11-27 03:24:32
问题 I have a data frame that has a format like the following: Month Frequency 2007-08 2 2010-11 5 2011-01 43 2011-02 52 2011-03 31 2011-04 64 2011-05 73 I would like to create a histogram from this data, using X bins (X will probably be around 15, but the actual data has over 200 months), and using the data from the frequency column as the frequency for each bin of the histogram. How can I accomplish this? I've tried two approaches so far, with the hist() and barplot() commands. The problem with

Normalizing a histogram and having the y-axis in percentages in matlab

痴心易碎 提交于 2019-11-27 02:55:25
问题 Edit: Alright, so I answered my own question, by reading older questions a bit more. I apologize for asking the question! Using the code Y = rand(10,1); C = hist(Y); C = C ./ sum(C); bar(C) with the corresponding data instead of the random data worked fine. Just need to optimize the bin size now. Good day, Now I know that you must be thinking that this has been asked a thousand times. In a way, you are probably right, but I could not find the answer to my specific question from the posts that

How to add gaussian curve to histogram created with qplot?

我怕爱的太早我们不能终老 提交于 2019-11-27 02:49:09
问题 I have question probably similar to Fitting a density curve to a histogram in R. Using qplot I have created 7 histograms with this command: (qplot(V1, data=data, binwidth=10, facets=V2~.) For each slice, I would like to add a fitting gaussian curve. When I try to use lines() method, I get error: Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet What is the command to do it correctly? 回答1: Have you tried stat_function ? + stat_function(fun = dnorm) You'll

3D histogram with gnuplot or octave

痞子三分冷 提交于 2019-11-27 02:23:34
问题 I would like to draw a 3D histogram (with gnuplot or octave) in order to represent my data. lets say that I have a data file in the following form: 2 3 4 8 4 10 5 6 7 I'd like to draw nine colored bars (the size of the matrix), in the set [1,3]x[1,3], such that the bar's color is proportional to the bar's height. How can I do this? 回答1: Below is a function I implemented that acts as a bar3 replacement (partially). In my version, the bars are rendered by creating a patch graphics object: we

Plotting a histogram from pre-counted data in Matplotlib

谁说我不能喝 提交于 2019-11-27 01:15:52
问题 I'd like to use Matplotlib to plot a histogram over data that's been pre-counted. For example, say I have the raw data data = [1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 10] Given this data, I can use pylab.hist(data, bins=[...]) to plot a histogram. In my case, the data has been pre-counted and is represented as a dictionary: counted_data = {1: 1, 2: 2, 3: 1, 4: 1, 5: 4, 6: 1, 10: 1} Ideally, I'd like to pass this pre-counted data to a histogram function that lets me control the bin widths, plot range,