Outlaw
Outlaw

Reputation: 359

Python Matplotlib required x_ticks don't appear on a radar chart

Ok, I'm plotting a radar chart with following wind direction data:

direction = ['N', 'NW', 'E', 'N', 'N', 'NW', 'NW', 'N', 'N', 'W', 'N', 'NW', 'NW', 'NW', 'N', 'SE', 'NE', 'E', 'E', 'NW', 'NE', 'S', 'E', 'W', 'W', 'NW', 'W', 'W', 'W', 'W', 'W', 'W', 'NW', 'W', 'W', 'W', 'W', 'W', 'W', 'NW', 'W', 'N', 'SE', 'E', 'NE', 'E', 'NE']

I collect list of attributes for ticks on the chart:

attributes = ['E', 'NE', 'N', 'NW', 'W', 'SW', 'S', 'SE']

Then I make list of values corresponding to each direction in attributes and angles of the axes to plot the data :

values = [6, 4, 8, 10, 16, 0, 1, 2, 6]
angles = [n / float(len(attributes)) * 2 * math.pi for n in range(len(attributes)[![enter image description here][1]][1])]
angles += angles [:1]

Then make a plot:

ax3 = plt.subplot(111, polar=True)
plt.xticks(angles[:-1], attributes)
ax3.plot(angles,values)
ax3.fill(angles, values, 'teal', alpha=0.1)
ax3.set_title("Direction")
plt.show()

And it works just fine (see pic_1). BUT when I use the same thing in my project, the ticks don't appear on the chart (see pic_2)! Here's the code (I have 4 sublots on the Figure, the radar chart is ax3 - bottom right one):

fig = plt.figure(figsize=(12, 8))
ax1 = plt.subplot2grid(gridsize, (0, 0))
ax2 = plt.subplot2grid(gridsize, (1, 0))
ax3 = plt.subplot2grid(gridsize, (1, 1), polar=True)
ax4 = plt.subplot2grid(gridsize, (0, 1))
[...ax1...]
[...ax2...]
[...ax4...]
ax3.set_xticks(angles[:-1], attributes)
ax3.plot(angles, values)
ax3.fill(angles, values, 'teal', alpha=0.1)
ax3.set_title('Направление ветра')
plt.show()

What's wrong with it?

pic_1 **with ticks**

pic_2 **no ticks**

Upvotes: 1

Views: 705

Answers (1)

If you are adding the ticks and tick labels to your axes (instead of using pyplot.xticks, as in your first snippet) you need to assign the tick locations and labels separately. Try the following, instead of ax3.set_xticks(angles, attributes) do:

ax3.set_xticks(angles)
ax3.set_xticklabels(attributes)

Upvotes: 2

Related Questions