import matplotlib.pyplot as plt
import numpy as np
labels=['Siege', 'Initiation', 'Crowd_control', 'Wave_clear', 'Objective_damage']
markers = [0, 1, 2, 3, 4, 5]
str_markers = ["0", "1", "2", "3", "4", "5"]
def make_radar_chart(name, stats, attribute_labels = labels, plot_markers = markers, plot_str_markers = str_markers):
labels = np.array(attribute_labels)
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats = np.concatenate((stats,[stats[0]]))
angles = np.concatenate((angles,[angles[0]]))
fig= plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, stats, 'o-', linewidth=2)
ax.fill(angles, stats, alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.yticks(markers)
ax.set_title(name)
ax.grid(True)
fig.savefig("static/images/%s.png" % name)
return plt.show()
make_radar_chart("Agni", [2,3,4,4,5]) # example
Basically I want the chart to be a pentagon instead of circle. Can anyone help with this. I am using python matplotlib to save an image which will stored and displayed later. I want my chart to have the form of the second picture
EDIT:
gridlines = ax.yaxis.get_gridlines()
for gl in gridlines:
gl.get_path()._interpolation_steps = 5
adding this section of code from answer below helped a lot. I am getting this chart. Still need to figure out how to get rid of the outer most ring:
The radar chart demo shows how to make the a radar chart. The result looks like this:
Here, the outer spine is polygon shaped as desired. However the inner grid lines are circular. So the open question is how to make the gridlines the same shape as the spines.
This can be done by overriding the
draw
method and setting the gridlines' path interpolation step variable to the number of variables of theRadarAxes
class.Complete example: