I am trying to plot mammalian feeding data on time points on a polar plot. In the example below, there is only one day, but each day will eventually be plotted on the same graph (via different axes). I currently have all of the aesthetics worked out, but my data is not graphing correctly. How do I get the hours to plot correctly?
I assume that the solution will likely have to do with pd.datetime and np.deg2rad, but I have not found the correct combo.
I am importing my data from csv, and filtering each day based on the date as follows:
#Filtered portion:
Day1 = df[df.Day == '5/22']
This gives me the following data:
Day Time Feeding_Quality Feed_Num
0 5/22 16:15 G 2
1 5/22 19:50 G 2
2 5/22 20:15 G 2
3 5/22 21:00 F 1
4 5/22 23:30 G 2
Here is the code:
fig = plt.figure(figsize=(7,7))
ax = plt.subplot(111, projection = 'polar')
ax.bar(Day1['Time'], Day1['Feed_Num'], width = 0.1, alpha=0.3, color='red', label='Day 1')
# Make the labels go clockwise
ax.set_theta_direction(-1)
#Place Zero at Top
ax.set_theta_offset(np.pi/2)
#Set the circumference ticks
ax.set_xticks(np.linspace(0, 2*np.pi, 24, endpoint=False))
# set the label names
ticks = ['12 AM', '1 AM', '2 AM', '3 AM', '4 AM', '5 AM', '6 AM', '7 AM','8 AM','9 AM','10 AM','11 AM','12 PM', '1 PM', '2 PM', '3 PM', '4 PM', '5 PM', '6 PM', '7 PM', '8 PM', '9 PM', '10 PM', '11 PM' ]
ax.set_xticklabels(ticks)
# suppress the radial labels
plt.setp(ax.get_yticklabels(), visible=False)
#Bars to the wall
plt.ylim(0,2)
plt.legend(bbox_to_anchor=(1,0), fancybox=True, shadow=True)
plt.show()
As you can assume from the data, all bars plotted would be in the afternoon, but as you can see from the graph output, the data is all over the place.