I recently was able to create some rose histograms (circular frequency histograms) in python with a great help from one of the python users in this forum. I would like now to add the labels on the top of the bars which correspond to the frequencies for each bar.
I was trying to use the following code but it represent all numbers around the circles which is messy and I only one to represent frequencies higher than 1. My frequencies are stored in file named frequencies.txt
This is the code I used:
# Import environmental variables from bash script
import sys, os
import numpy as np
#Load text in variable
frequencies = np.loadtxt('frequencies_'+str(second_count)+'-new.txt')
print (frequencies)
fig = plt.figure()
ax = plt.axes(polar=True)
# Define the torsion angles
theta = np.radians(np.arange(0, 360, 10))
angles= np.radians(np.arange(0, 360, 45))
# Determine the width of the bins
width = np.radians(10)
# Fiddle with labels and limits
ax.tick_params(axis='x', colors='black', labelsize='8')
ax.tick_params(axis='y', colors='green', labelsize='10')
plt.xticks(weight = 'bold')
plt.yticks(weight = 'bold')
# Define the grid of the rose diagram
ax.yaxis.grid(True,color='k',linestyle='--', linewidth=0.5)
ax.xaxis.set_visible(True)
ax.set_facecolor('xkcd:white')
ax.grid(True)
# Represent the rose diagram
bars = ax.bar(theta, frequencies, width = width, edgecolor = 'black', align = 'edge', facecolor='gray', linewidth = 0.4)
# Add line representing the circular mean
arr2 = plt.arrow(float(circular_mean)/180.*np.pi, 0, 0, int(max_freq), width = 0.020, edgecolor = 'black', facecolor = 'red', lw = 0.3, head_length = 20, head_width = 0.08)
# Representing the labels around the circle
ax.set_xticks(theta)
ax.set_rlabel_position(90)
# Add labels to each bar depending on the frequency
bottom = 50[enter image description here][1]
rotations = np.rad2deg(theta)
for x, bar, rotation, label in zip(theta, bars, rotations, lObjectsALLlbls):
lab = ax.text(x,bottom+bar.get_height() , label,
ha='left', va='center', rotation=rotation, rotation_mode="anchor",)
plot.show()
My frequencies are listed in a one column frequencies.txt file in the following way:enter code here
0
0
0
0
0
2
0
1
1
0
1
0
0
1
2
29
108
262
290
184
81
25
7
2
3
1
1
0
0
0
0
0
0
0
0
0