编辑标签和轴限制的雷达图
Editing Radar Charts for Labeling and Axis Limits
我一直在研究 radar chart
可视化基于百分比的指标的概念。我遵循了示例代码,但在处理一些项目时遇到了问题。谁能帮我将标签从默认度数值更改为其他值?我也想将 x 轴最小值设置为 0.9,但有点挣扎。
任何帮助或资源都是有帮助的。如果有更有效的方法解决它们,我愿意重新开始。
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()
正如您在评论中所显示的那样,围绕圆的标签为 xticklabels
,沿半径的标签为 yticklabels
,即 y 轴沿半径。因此,我认为你的意思是 "set the y-axis minimum to 0.9".
正如您对常规绘图所做的那样,您可以使用 set_xticks
结合 set_xticklabels
来更改 "the labels from the default degree values to something else"。例如:
ax.set_xticks([np.pi/4, np.pi*3/4])
ax.set_xticklabels(['NE', 'NW'])
到"set the y-axis minimum to 0.9",你可以这样使用set_ylim
:
ax.set_ylim(0.9, 1)
我一直在研究 radar chart
可视化基于百分比的指标的概念。我遵循了示例代码,但在处理一些项目时遇到了问题。谁能帮我将标签从默认度数值更改为其他值?我也想将 x 轴最小值设置为 0.9,但有点挣扎。
任何帮助或资源都是有帮助的。如果有更有效的方法解决它们,我愿意重新开始。
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()
正如您在评论中所显示的那样,围绕圆的标签为 xticklabels
,沿半径的标签为 yticklabels
,即 y 轴沿半径。因此,我认为你的意思是 "set the y-axis minimum to 0.9".
正如您对常规绘图所做的那样,您可以使用 set_xticks
结合 set_xticklabels
来更改 "the labels from the default degree values to something else"。例如:
ax.set_xticks([np.pi/4, np.pi*3/4])
ax.set_xticklabels(['NE', 'NW'])
到"set the y-axis minimum to 0.9",你可以这样使用set_ylim
:
ax.set_ylim(0.9, 1)