In [1]:
using PyPlot
In [2]:
## code date
codedate = "151116"

## matplotlib settings
# fonttype = "serif"
fonttype = "sansserif"
# PyPlot.matplotlib[:rc]("text", usetex=true) # allow tex rendering
# PyPlot.matplotlib[:rcParams]["text.latex.unicode"] = true
if fonttype=="serif" # use serif math font
    PyPlot.matplotlib[:rc]("font", family="serif", serif="Times", size=16)
#     PyPlot.matplotlib[:rc]("text.latex",preamble="\\usepackage{newtxmath}")
else # use sans serif math font
    PyPlot.matplotlib[:rc]("font", family="sans-serif", size=16)
#     PyPlot.matplotlib[:rc]("text.latex",preamble="\\usepackage{newtxsf}")
end
# PyPlot.matplotlib[:rcParams]["text.latex.unicode"] = false

figtype = "png"
Out[2]:
"png"
In [3]:
function drawRadar(fname,items,layers,maxRadius,tickSize,layerNames,layerColors)
    ## calculations
    nItems = length(items) # number of properties
    tht = 2*pi/nItems # equal angle
    thetas = 0.5*pi:tht:2.49*pi # collection of angles
    nLayers = length(layers) # number of layers
    # for layer in layers # scale values
    #     layer *= maxRadius/9
    # end

    ## set up canvas
    fig = PyPlot.figure(figsize=(8,6), facecolor="w", dpi=120) # create figure
    fig[:subplots_adjust](left=.2, right=.9, bottom=0.1, top=.9) # reduce white spaces
    ax = fig[:add_subplot](111,projection="polar") # create axis
    ax[:spines]["polar"][:set_visible](false) # hide the outermost circle
    ax[:set_yticklabels]([]) # turn off y-axis (length-axis)
    ax[:grid](false) # no circle-shaped grids

    ## draw axes
    for j = 1:nItems # draw line toward each property
        ax[:plot]([0,.5*pi+tht*j],[0,maxRadius], color="darkgray", lw="0.5", zorder=2)
    end
    for r in tickSize:tickSize:maxRadius # draw level lines
        ax[:plot]([thetas;pi/2],r*ones(nItems+1), color="darkgray", lw="0.3", zorder=1)
    end

    ## plot layers
    for (j,layer) = enumerate(layers) # plot each layer
        ax[:plot]([thetas;pi/2],[layer;layer[1]], color=layerColors[j], lw=1.5, zorder=500-j, label=layerNames[j]) # line
        ax[:fill](thetas,layer, color=layerColors[j], alpha=0.15, zorder=100-j) # shade
        ax[:scatter](thetas,layer, marker="o", s=81, linewidths=2, facecolor=layerColors[j], edgecolor="white", zorder=1000-j) # dots
    end

    ## set ax properties
    ax[:set_xticks](thetas) # set ticks on x-axis (angle-axis)
    ax[:set_xticklabels](items, size=14, color="gray") # label properties
    ax[:set_ylim]([0,maxRadius*1.03]) # set radius limits

    ## legend
    lg = PyPlot.legend(bbox_to_anchor=(0, 1.1), prop=Dict("size"=>13), framealpha=0.0)
    lg[:draw_frame](false) # no box around legend

    ## save figure
    fig[:savefig]("./$codedate-$fname.$figtype", transparent=true, rasterized=true)
    
    ## return
    return fig
end
Out[3]:
drawRadar (generic function with 1 method)
In [4]:
### data

## item names


## item dictionary
itemDict = Dict( # in the order of interest, exposure, effort
    "\nBikes"                        =>[ 2, 6, 7],
    "Contract bridge"                =>[ 8, 4, 5],
    "Coding"                         =>[ 4, 6, 9],
    "Economics"                      =>[ 6, 7, 8],
    "Food"                           =>[ 3, 2, 4],
    "À la recherche\ndu temps perdu" =>[ 7, 3, 2],
    "Linguistics"                    =>[ 6, 1, 2],
    "\nMarket\nmicrostructure"       =>[ 8, 9,9.8],
    "Physics"                        =>[ 8, 4, 3],
    "Poetry\n(in Chinese)"           =>[10, 8, 7],
    "Shanghai"                       =>[ 5,10, 1],
    "Shogi"                          =>[ 9, 4, 6],
    "Technology"                     =>[ 6, 5, 3],
)

## assign to items and layers
items = [item for item in keys(itemDict)]
layer1 = convert(Array{Number,1},[itemDict[x][1] for x in items]) # interest
layer2 = convert(Array{Number,1},[itemDict[x][2] for x in items]) # exposure
layer3 = convert(Array{Number,1},[itemDict[x][3] for x in items]) # effort
layers = Array{Float64,1}[layer1, layer2, layer3];
In [5]:
### the politically correct version

itemsPC = ["Judy";items]
layersPC = Array{Float64,1}[[9.4;layer1/10], [8;layer2/10], [10;layer3/10]];

# nItems = length(items)
# itemsPC = ["Judy" for j=1:nItems]
# layersPC = Array{Float64,1}[10*ones(nItems), 8*ones(nItems), 12*ones(nItems)];
In [6]:
### graph parameters

maxRadius = 10
tickSize = 2

layerNames = ["interest","exposure","effort"] # names of each layer
layerColors = ["#FF6A00","gray","#006AFF"] # larger layer number means lower zorder
Out[6]:
3-element Array{ASCIIString,1}:
 "#FF6A00"
 "gray"   
 "#006AFF"
In [7]:
## draw radar
drawRadar("interests",items,layers,maxRadius,tickSize,layerNames,layerColors)
Out[7]:
In [8]:
## draw politically correct radar
drawRadar("interestsPC",itemsPC,layersPC,maxRadius,tickSize,layerNames,layerColors)
Out[8]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: