Jun-13-2019, 09:22 AM
I am trying to color sections of this graph by dividing it into times from dawn to sunset and from sunset to dawn (next day).
The graph looks (almost) exactly the way I want,but when I uncomment line 28 and 29 to span the colors throughout the times mentioned above, I get an almost empty graph with the hours overlapping each other to the left.
How do I fix this problem?
The graph looks (almost) exactly the way I want,but when I uncomment line 28 and 29 to span the colors throughout the times mentioned above, I get an almost empty graph with the hours overlapping each other to the left.
How do I fix this problem?
from astral import Astral
import numpy as np
import matplotlib.pyplot as plt
import datetime
import pytz
import sys
date_list = [date(2015, 5, 12), date(2015, 5, 13), date(2015, 5, 14)]
data1 = range(47)
data2 = [0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 1, 2, 4, 4, 0, 0, 0,
0, 0, 0, 0, 0, 10, 2, 0, 1, 0, 1, 0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0]
CEU_times1=datetime.datetime(2015, 5, 12, 3, 0, 5, 597773)
CEU_times2=datetime.datetime(2015, 5, 12, 3, 0, 5, 597773)
time_list=[CEU_times1 + datetime.timedelta(hours=i) for i in range(0,len(data2))]
hours=[time_list[i].time() for i in range(0,len(data2),3)]
city_name = 'Copenhagen'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]
sun1=city.sun(date=(CEU_times1), local=True)
sun2=city.sun(date=(CEU_times2), local = True)
#plt.axvspan(sun1['dawn'],sun1['sunset'],facecolor='green', alpha=3) ## the graph looks ok as long as these
#plt.axvspan(sun1['sunset'], sun2['dawn'], facecolor='orange',alpha=3) ## two lines remain commented
plt.bar(data1,data2, width=1, color='blue' )
plt.xticks(range(1, len(data2),3 ),hours, rotation=45)
plt.gcf().autofmt_xdate()
plt.twiny()
plt.xticks((1,23,45), date_list, rotation=45)
plt.show()
