<jupyter_start><jupyter_text>Very simple radar mapLearn at https://zhuanlan.zhihu.com/p/37104717<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']

name = ['语文','数学','英语','物理','化学']   #标签
theta = np.linspace(0,2*np.pi,len(name),endpoint=False)    #将圆根据标签的个数等比分
value = np.random.randint(50,100,size=5)   #在60-120内，随机取5个数
theta = np.concatenate((theta,[theta[0]]))  #闭合
value = np.concatenate((value,[value[0]]))  #闭合

ax = plt.subplot(111,projection = 'polar')      #构建图例
ax.plot(theta,value,'m-',lw=1,alpha = 0.75)    #绘图
ax.fill(theta,value,'m',alpha = 0.75)           #填充
ax.set_thetagrids(theta*180/np.pi,name)         #替换标签
ax.set_ylim(0,110)                          #设置极轴的区间
ax.set_theta_zero_location('N')         #设置极轴方向
ax.set_title('五维图',fontsize = 20)   #添加图描述
plt.show()<jupyter_output><empty_output><jupyter_text>Advanced radar mapLearn at http://sofasofa.io/tutorials/radar_plot/<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
data = pd.read_csv('cities_ranking.csv')
data.head()
def plot_radar(data, city):
    '''
    data是上面读入的原始数据
    city是要显示的城市，可以是一个城市，比如city="上海"
    也可以是一组城市，比如city=["杭州", "南京"]
    为了视觉效果，最多同时展示5个城市。
    '''
    if type(city) != list: city = [city]

    # 从下面六项指标，体现城市发展水平
    cols = ['文化', '科教', '经济产值', '财富储蓄', '环境', '卫生']

    # 每个城市的配色
    colors = ['green', 'blue', 'red', 'yellow', 'black']

    # 把圆形进行六等分
    angles = np.linspace(0.1 * np.pi, 2.1 * np.pi, len(cols), endpoint=False)
    angles = np.concatenate((angles, [angles[0]]))

    # 初始化一个极坐标图像
    fig = plt.figure(figsize=(6, 6))
    ax = fig.add_subplot(111, polar=True)

    # 逐一添加每个城市图像以及排名信息
    for i, c in enumerate(city):
        rank = data.loc[data['城市'] == c, '排名'].values[0]
        stats = data.loc[data['城市'] == c, cols].values[0].tolist()
        stats = np.concatenate((stats, [stats[0]]))
        ax.plot(angles, stats, '-', linewidth=6, c=colors[i], label='%s 排名第%s'%(c, rank))
        ax.fill(angles, stats, c=colors[i], alpha=0.25)

    # 添加图例
    ax.legend(loc=[0.25, 1.15], fontsize=18)
    ax.set_yticklabels([])
    ax.set_thetagrids(angles * 180/np.pi, cols, fontsize=16)
    ax.grid(True)

    # 完成
    plt.show()
    return fig
plot_radar(data, "上海");
#城市对比
plot_radar(data, ['北京', '上海']);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18403639371381306, 'fraction_numerical': 0.030603804797353185, 'mean_word_length': 3.8283433133732534, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '336518', 'license': 'MIT', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1182, 'n_words': 167, 'path': 'Radar map/radar map.ipynb', 'repo_name': 'haoruilee/statistics-graphs', 'size': '2418'}