Holland personality analysis radar chart

Radar Chart Radar Chart

Radar chart is an important way to visually display multiple characteristics

problem analysis

Holland believes that there should be an internal correspondence between personality interests and occupations

Personality categories: Research, Artistic, Social, Entrepreneurial, Traditional, Realistic

Occupations: Engineer, experimenter, artist, salesman, scribe, social worker

Requirement: Radar chart method to verify Holland's personality analysis - Input: Research data of various occupational groups combined with interests - Output: Radar chart

analyze:

The function of this code is to draw a radar chart in the polar coordinate system, which contains the data of the occupation type and the corresponding 6 trait scores. Specific steps are as follows:

  1. Import the required libraries: numpy and matplotlib.pyplot.

  2. Set Chinese label display: set the default font to Chinese bold.

  3. Definition data: a matrix of 6 rows and 6 columns, representing 6 trait scores of 6 occupations.

  4. Define the angle: Use numpy's linspace function to generate 6 angles as the x-axis coordinates of the radar chart.

  5. Repeat first angle: To close the image, add the first angle to the end of the array.

  6. Define Occupation Tags: a list of 7 string elements.

  7. Draw a radar chart: Draw a graph of the trait score for each profession through a loop. In the loop, use the ax.plot function to draw a line graph of the trait scores and use the ax.fill function to fill in the colors.

  8. Add coordinate axis labels: Use the ax.set_thetagrids function to add labels for the angle axis.

  9. Add a title: Use the plt.title function to add a chart title.

  10. Add legend: Use the plt.legend function to add a legend.

  11. Display graphics: Use the plt.show function to display graphics.

code: 

# -- coding: utf-8 --
import numpy as np
import matplotlib.pyplot as plt
# 如果需要使用中文标签,还需添加以下代码
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定默认字体为中文黑体
# 数据
data = [[0.40, 0.32, 0.35, 0.30, 0.30, 0.88],
        [0.85, 0.75, 0.30, 0.25, 0.20, 0.40],
        [0.43, 0.89, 0.30, 0.28, 0.22, 0.30],
        [0.20, 0.30, 0.85, 0.45, 0.32, 0.25],
        [0.19, 0.22, 0.40, 0.90, 0.92, 0.28],
        [0.62, 0.55, 0.27, 0.25, 0.35, 0.30]]

# 角度(弧度)
angles = np.linspace(0, 2*np.pi, 6, endpoint=False)

# 重复第一个角度以使图像闭合
angles = np.concatenate((angles, [angles[0]]))

# 职业
occupations = ['工程师', '实验员', '艺术家', '推销员', '记事员', '社会工作者', '技术员']

# 绘图
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
for i in range(len(data)):
    # 绘制折线图
    ax.plot(angles, data[i]+data[i][:1], 'o-', linewidth=2, label=occupations[i])
    # 填充颜色
    ax.fill(angles, data[i]+data[i][:1], alpha=0.25)
# 添加坐标轴标签
ax.set_thetagrids(angles*180/np.pi, occupations)
# 添加标题
plt.title('Holland Personality Analysis', fontsize=20)
# 添加图例
plt.legend(loc='best')
# 显示图形
plt.show()

Effect:

 

Guess you like

Origin blog.csdn.net/weixin_64612659/article/details/130396398