Rivers31334
Rivers31334

Reputation: 654

Editing Radar Charts for Labeling and Axis Limits

I have been playing with the radar chart concept for visualizing percentage-based metrics. I have followed sample code but am having trouble with a few items. Can anyone help me with changing the labels from the default degree values to something else? I also want to set the x-axis minimum to 0.9, but struggled a bit.

Any help or resources are helpful. If there is a more efficient way to solve them, I am open to starting over again.

import numpy as np
import matplotlib.pyplot as plt

availability_array = np.array([.95, .9, .99, .97, 1]) #sample inverter uptime availability numbers using site with 5 inverters

# Compute pie slices
theta = np.linspace(0.0, 2 * np.pi, len(availability_array), endpoint=False)
values = availability_array #values that are graphed
width = 1 #increase/decrease width of each bar

ax = plt.subplot(111, projection='polar') #.set_xticklabels(['N', '', 'W', '', 'S', '', 'E', '']) #111 means 1x1 grid subplot starting in cell 1

bars = ax.bar(theta, values, width=width, bottom=0.0)

# Coloring
for r, bar in zip(values, bars):
    bar.set_facecolor(plt.cm.viridis(r / 1))
    bar.set_alpha(0.4) #transparency of the bars

plt.show()

Upvotes: 0

Views: 2531

Answers (1)

Y. Luo
Y. Luo

Reputation: 5732

As you've already shown in your comments, labels around the circle are xticklabels and labels along the radius are yticklabels, i.e. y-axis is along the radius. Therefore, I think you meant to "set the y-axis minimum to 0.9".

As you would do with regular plot, you can use set_xticks in combine with set_xticklabels to change "the labels from the default degree values to something else". For example:

ax.set_xticks([np.pi/4, np.pi*3/4])
ax.set_xticklabels(['NE', 'NW'])

To "set the y-axis minimum to 0.9", you can use set_ylim like this:

ax.set_ylim(0.9, 1)

Upvotes: 3

Related Questions