Plot a histogram without the zero values in python?

Viewed 17756

When I try to make a histogram without the zero values, I get an error:

Traceback (most recent call last):.

I have a list of Beam_irradiance_DNI values which include several zeroes. I can make histogram, but I don't want the zero values.

import matplotlib.pyplot as plt
import numpy as np

import csv

# Reading data from csv file
with open('Upington_DNI.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
Hour_of_year = []
Beam_irradiance = []
for row in readCSV:
    hour = row[0]
    DNI = row[1]
    Hour_of_year.append(hour)
    Beam_irradiance.append(DNI)
Hours_since00hrsJan1 = [float(Hour_of_year[c]) for c in       range(1,len(Hour_of_year))]
Beam_irradiance_DNI=[float(Beam_irradiance[c]) for c in range(1,len(Beam_irradiance))]

plt.figure(3)
Beam_irradiance_DNI[ Beam_irradiance_DNI==0 ] = np.nan
plt.hist(Beam_irradiance_DNI, color="grey")
plt.title("Histogram for Beam irradiance - DNI")
plt.xlabel("Beam irradiance - DNI [W/m2]"); plt.ylabel("Probability of  occurrence")
plt.show()

I dont know what is wrong here.

2 Answers
Related