Вот некоторый код, который я должен построить гистограмму аномалий осадков.Я хочу показать отрицательные значения другим цветом.Я попытался найти некоторые вещи, и мне кажется, что мне нужно создать другой список для отрицательных значений с двумя подзаговорами.Есть ли более простой способ сделать это?
def delta_mean_precipitation():
"""Delta_mean_precipitation addresses task 7 of the project and is a function that takes no arguments and gives us the
rate of change in average precipitation year-to-year. The goal is to create a bar chart representing the change in value
of global mean precipitation between each pair of consecutive years. A lot of the code is similar to the the anomoly code
"""
data=np.load('annual_precip.npy') #load the data
data=data.astype(np.float) #convert type to float
yearly_precip=[] #this will only have 115 values
for i in range(115):
rate_of_change=[] #create an empty array called rate of change. This will account for ALL the years
for j in range (85794):
avg_precip=data[i][j][4]
rate_of_change.append(float(avg_precip))#add all the average values to the empty array
yearly_precip.append(sum(rate_of_change)/(85794)) #sicne I want the average for each year, I will make an array with ALL of the data from the year and then take the average. The average will then be added to a new list.
year_to_year=[] #create an empty array
for k in range(114):
year_to_year.append(yearly_precip[k]-yearly_precip[k-1]) #add to the list by using the yearly_precip array
x=[i for i in range (1901,2015)] #line 199 - 205 are plot parameters
y=year_to_year
pl.figure(figsize=(16,8))
pl.bar(x,y)
pl.title('Rate of change in global annual mean precipition between 1900 and 2014')
pl.xlabel('Year')
pl.ylabel('Rate of change in mean precipitation mL/year')
pl.show