0

A similar question has already been asked on this: Plotting profile histograms in python. But never the less, it won't work for me, for some reason.

Let's look at my code

 from pylab import *
 import numpy as np
 import matplotlib.pyplot as plt
 import seaborn as sns
 import scipy


 file = open('cesium.txt','r')
 count = 0
 energy_channel = []
 intensity_counts = []
 for line in file.readlines():
     count += 1
     if count >= 10:
         row = line.split()
         int_1 = int(row[0])
         int_2 = int(row[-1])
         energy_channel.append(int_1)
         intensity_counts.append(int_2)
     if count == 2700: break


 plt.plot(energy_channel, intensity_counts, 'k.')
 plt.xlabel('Energy (keV)')
 plt.ylabel('Counts')
 plt.xticks([0, 400, 800, 1200, 1600, 2000, 2400],
            [0, 110, 220, 330, 440, 550, 662])
 plt.show()
 plt.clf()

This will plot a so called a gamma-spectrum for the radioactive isotope Cs-137 (for those who are intrested). Now, I would like to make a profile histogram out of this spectrum. Since I have all the points stored in the the two (x- and y-) vectors energy_channel and intensity_counts, respectively, I thought something like this might work:

scipy.stats.binned_statistic(energy_channel,intensity_counts)

But this simply gives me an error message:

 FutureWarning:
 Using a non-tuple sequence for multidimensional indexing is deprecated;
 use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be
 interpreted as an array index, `arr[np.array(seq)]`, which will result
 either in an error or a different result.

I hope I am clear in my question here. I would like to make a profile histogram like in the thread I put a link to, but it doesn't seem to work as I think it will, and I can't figure it out.

Edit: I have tried making the lists into a tuple-list with the function zip() and then give it to the binned_statistics() function, but the same error message appears. I also tried making the lists into sequences, but it didn't seem to work either.

Rohan Nadagouda
  • 462
  • 7
  • 18
  • What you are seeing is a warning, not an Error. The warning can be safely ignored, it just means something in scipy's code will have to change to maintain the correct behavior. However, do you get an Error? do you get an output? – Diziet Asahi Nov 15 '18 at 21:34
  • What you get is a warning, not an error. This warning will as of now not influence how the result is calculated. There is also little you can do about the warning; it is something scipy has to workaround for the next release. That being said, what *actual* problem do you encounter? Does the plot not show up? Does it show but looks unexpected? If so, in how far? – ImportanceOfBeingErnest Nov 15 '18 at 21:34
  • I see, no I don't get an output or a figure of the diagram as anticipated. I (thought) I should get the so called profile histogram, but nothing appears, only the warning. – SimpleProgrammer Nov 15 '18 at 23:39
  • So how are you running this code? What is the purpose of `plt.clf()` in the last line of it? – ImportanceOfBeingErnest Nov 16 '18 at 13:02

0 Answers0