[PYTHON] Code for self-analysis and radar chart creation

All you have to do is interactively answer simple questions and create a radar chart

python.py


import matplotlib.pyplot as plt
import numpy as np
import os
import pathlib
import datetime
import time
import platform
import datetime

from googletrans import Translator

def trans(trsTarget_li):
    translator = Translator()
    jp_words = trsTarget_li
    en_words = []

    for src in jp_words:
        dst = translator.translate(src, src='ja', dest='en')
        en_words.append(dst.text)

    return(en_words) 

def plot_polar(labels, values, imgname):
    angles = np.linspace(0, 2 * np.pi, len(labels) + 1, endpoint=True)
    values = np.concatenate((values, [values[0]]))  #Make it a closed polygon
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=True)
    ax.plot(angles, values, 'o-')  #Outer frame
    ax.fill(angles, values, alpha=0.25)  #fill
    ax.set_thetagrids(angles[:-1] * 180 / np.pi, labels)  #Axis label
    ax.set_rlim(0 ,100)
    fig.savefig(imgname)
    plt.close(fig)

def viz(file_name):
    print('Please give what you value')
    li = input().split()

    rate_li = []
    for i in li :
        print(i+'Please enter the ratio of importance')
        a=int(input())
        rate_li.append(a)

    labels = trans(li)
    values = rate_li
    plot_polar(labels, values,file_name+'.jpg')

viz('filename')

The png is saved like this

スクリーンショット 2020-06-22 21.33.58.png

reference https://teratail.com/questions/168918 https://qiita.com/1007/items/80406e098a4212571b2e

Recommended Posts

Code for self-analysis and radar chart creation
Interactive console application for address and zip code search
Comfortable LaTeX with Windows Subsystem for Linux and VS Code