Python Forum
plot the mean in a bar diagram
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plot the mean in a bar diagram
#1
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()
plt.bar(ind, y, align='center')
plt.xticks(ind, labels)
plt.show()
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\labb.py", 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!
Reply


Messages In This Thread
plot the mean in a bar diagram - by sussii - May-23-2018, 03:47 PM
RE: plot the mean in a bar diagram - by wavic - May-23-2018, 11:11 PM
RE: plot the mean in a bar diagram - by sussii - May-23-2018, 11:18 PM
RE: plot the mean in a bar diagram - by wavic - May-23-2018, 11:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to simulate this block diagram with python control library? nugrohoav 1 6,419 May-21-2017, 12:39 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020