Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 plot the mean in a bar diagram
Hi, I need some help with writing a code.
I have a text file where it contains number of decays per second. I want to make a bar diagram of the distribution of number of decays per 5 second intervals and calculate and enter mean and plot in the same graph the poisson distribution, normalized to the number of events in the chart that has this mean.

I dont really understand how to do and appreciate all the help I can get.

I started this way:

import numpy as np
from spicy.stats import poisson
from matplotlib import pyplot as plt

#I think that we want to take the readings from the text file (it called backgroundb)

with open('backgroundb.txt') as f:
lines = [line.strip().split(',') for line in f if len(line) > 1]
labels, y = zip(*lines)
ind = np.arange(len(labels))
plt.figure(), y, align='center')
plt.xticks(ind, labels)

The text file contains:
0 5
1 10
2 1
3 2
4 8
5 1
6 4
7 6
8 1
9 3
(contains more values but I wanted to show how the text file looks like)
I have the text file in my desktop and I do not know if it depends on it and I do not know how to continue.

I get error like:
Traceback (most recent call last):
File "C:\Users\sibel\Desktop\", line 8, in <module>
labels, y=zip(*lines)
ValueError: not enough values to unpack (expected 2, got 1)

And i dont know what I need to change.

All help is appreciated!
See the content of the file ( backgroundb.txt ). Obviously, the if statement (if len(line) > 1)isn't accurate and is not working.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
(May-23-2018, 11:11 PM)wavic Wrote: See the content of the file ( backgroundb.txt ). Obviously, the if statement (if len(line) > 1)isn't accurate and is not working.

But what can I write instead of if len(line) > 1? The textfile contains 352 seconds and decay for each second.
Oh! In your post, you are showing the file content. Well, why do you split by comma where the values are separated by space? There is no comma, so there is no splitting of the line and you get the whole line - one value.

And why zip()? You get already a list of two values which you can unpack.
>>> line = "4 8"
>>> line.split()
['4', '8']
The last one is stupig. Don't pay attention on it. :D
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to create a new plot in a figure right below the first one after click event? codexx 0 28 Yesterday, 04:45 PM
Last Post: codexx
  How do I make my plot show up? ThomasM4 0 267 Dec-09-2018, 05:28 AM
Last Post: ThomasM4
  Tips on surface plot HW question Cwcox 1 331 Nov-14-2018, 11:45 PM
Last Post: Larz60+
  How to customize x axis in matplotlib.pyplot for a scatter plot? wlsa 9 671 Nov-10-2018, 01:32 AM
Last Post: wlsa
  Adding text to plot Pythcoronas 1 404 Sep-13-2018, 12:27 PM
Last Post: baby_quant
  How to plot date series in matplotlib? StrybolData 2 2,301 Jan-25-2018, 07:13 PM
Last Post: StrybolData
  Removing data in a plot ulrich48155 3 1,405 Jun-19-2017, 06:31 PM
Last Post: zivoni
  How to simulate this block diagram with python control library? nugrohoav 1 2,082 May-21-2017, 12:39 PM
Last Post: sparkz_alot
  How to plot a Graph Kamo 2 1,476 May-12-2017, 12:22 PM
Last Post: zivoni
  matplotlib : Raster Plot adithyakrish 0 1,193 Apr-24-2017, 10:46 AM
Last Post: adithyakrish

Forum Jump:

Users browsing this thread: 1 Guest(s)