Search code examples
matplotlibsubplotradar-chart

Use radar chart in a subplot


I used this code to produce a radar chart: Radar chart with multiple scales on multiple axes; now I want to place this chart in bottom right corner of a 2x1 figures set-up. Using the code below:

fig = pl.figure(figsize=(5, 5))

titles = ['A','B','C','D','E','F']
parameters_list = ['','2','','4','','6','','8','','10']
labels = [parameters_list, parameters_list, parameters_list,parameters_list,parameters_list,parameters_list]
radar = Radar(fig, titles, labels)

pl.subplot(2, 1, 1)
radar.plot([1, 3, 2, 5, 4, 9],  "-", lw=2, color="r", alpha=0.4, label="first")
pl.subplot(2, 1, 2)
radar.plot([3, 6, 4, 1, 1, 2],  "-", lw=2, color="y", alpha=0.4, label="second")

this yields two blank boxes, while I would like to get two radar charts, one above the other (see link below).

[1]: https://i.sstatic.net/oaXzf.png - two blank boxes

If I try to create a single radar chart, the code works correctly (see code and link below):

fig = pl.figure(figsize=(5, 5))
titles = ['A','B','C','D','E','F']
parameters_list = ['','2','','4','','6','','8','','10']
labels = [parameters_list, parameters_list, parameters_list,parameters_list,parameters_list,parameters_list]
radar = Radar(fig, titles, labels)

radar.plot([1, 3, 2, 5, 4, 9],  "-", lw=2, color="r", alpha=0.4, label="first")
radar.ax.legend()

[2]: https://i.sstatic.net/LnL6e.png - radar chart working correctly

How can I get the two radar charts one above the other? Or how can I insert the radar in a subplot while the other subplots show different kind of chart?


Solution

  • Since you are using the Radar class given in HYRY's answer in Radar chart with multiple scales on multiple axes, here's a solution using that:

    fig = pl.figure(figsize=(5, 5))
    
    titles = ['A','B','C','D','E','F']
    parameters_list = ['','2','','4','','6','','8','','10']
    labels = [parameters_list, parameters_list, parameters_list,parameters_list,parameters_list,parameters_list]
    
    radar = Radar(fig, titles, labels, rect=[0.0, 0.55, 0.5, 0.45])
    radar.plot([1, 3, 2, 5, 4, 9],  "-", lw=2, color="r", alpha=0.4, label="first")
    
    radar = Radar(fig, titles, labels, rect=[0.0, 0.0, 0.5, 0.45])
    radar.plot([3, 6, 4, 1, 1, 2],  "-", lw=2, color="y", alpha=0.4, label="second")
    

    Result:

    enter image description here

    I used the optional rect parameter in that class, which provides sizes for [left, bottom, width, height] relative to the full figure.

    Having done so, I don't know why you chose to use a class that is meant for displaying multiple scales, since you only seem to have a single scale (duplicated 6 times in the labels array), so I have to assume you have a good reason.