1

I'm trying to move the radar plot on the end of the first row downwards so it's middle way between the first and second row. I have no idea where to even start to attempt this. I've added the desired location of the plot.

enter image description here

Some code to reproduce the problem is here:

import math
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

def make_spider(row, title, color, ax=None):

    categories=list(radar_dfs)
    N = len(categories)
    angles = np.arange(N+1)/N*2*np.pi
    values=radar_dfs.iloc[row].values.flatten().tolist()
    values += values[:1]
    ax.plot(angles, values, color=color,linewidth=2, linestyle='solid')
    ax.fill(angles, values, color=color, alpha=0.4)

radar_dfs = pd.DataFrame.from_dict({"no_rooms":{"0":-0.3470532925,"1":-0.082144001,"2":-0.082144001,"3":-0.3470532925,"4":-0.3470532925},"total_area":{"0":-0.1858487321,"1":-0.1685491141,"2":-0.1632483955,"3":-0.1769700284,"4":-0.0389887094},"car_park_spaces":{"0":-0.073703681,"1":-0.073703681,"2":-0.073703681,"3":-0.073703681,"4":-0.073703681},"house_price":{"0":-0.2416123064,"1":-0.2841806825,"2":-0.259622004,"3":-0.3529449824,"4":-0.3414842657},"pop_density":{"0":-0.1271390651,"1":-0.3105853643,"2":-0.2316607937,"3":-0.3297832328,"4":-0.4599021194},"business_rate":{"0":-0.1662745006,"1":-0.1426329043,"2":-0.1577528867,"3":-0.163560133,"4":-0.1099718326},"noqual_pc":{"0":-0.0251535462,"1":-0.1540641646,"2":-0.0204666924,"3":-0.0515740013,"4":-0.0445135996},"level4qual_pc":{"0":-0.0826103951,"1":-0.1777759951,"2":-0.114263357,"3":-0.1787044751,"4":-0.2709496389},"badhealth_pc":{"0":-0.105481688,"1":-0.1760349683,"2":-0.128215043,"3":-0.1560577648,"4":-0.1760349683}})

fig, axes = plt.subplots(2, 3, subplot_kw=dict(polar=True), sharey=True,
                         figsize=(28,20))

palette =['#79BD9A','#69D2E7','#F38630', '#547980','#EDC951']
labels = ['A', 'B', 'C', 'D', 'E']


row_one = axes.flatten()
for row, (ax, letter, col) in enumerate(zip(row_one, labels, palette)):
    make_spider( row  = row, title='Group ' + str(letter), color=col, ax=ax)

fig.delaxes(axes[1][2])
plt.subplots_adjust(wspace=.4, hspace=.3)
plt.show() 

Does anybody have any advice?

Sam Comber
  • 1,237
  • 1
  • 15
  • 35

1 Answers1

2

One way to do so would be to create each subplot with plt.subplot2grid() and locating them manually. A trick that can be used is to double the number of rows and the height of each chart, which will allow to tune the location more finely.

import math
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

def make_spider(row, title, color, ax=None):

    categories=list(radar_dfs)
    N = len(categories)
    angles = np.arange(N+1)/N*2*np.pi
    values=radar_dfs.iloc[row].values.flatten().tolist()
    values += values[:1]
    ax.plot(angles, values, color=color,linewidth=2, linestyle='solid')
    ax.fill(angles, values, color=color, alpha=0.4)

radar_dfs = pd.DataFrame.from_dict({"no_rooms":{"0":-0.3470532925,"1":-0.082144001,"2":-0.082144001,"3":-0.3470532925,"4":-0.3470532925},"total_area":{"0":-0.1858487321,"1":-0.1685491141,"2":-0.1632483955,"3":-0.1769700284,"4":-0.0389887094},"car_park_spaces":{"0":-0.073703681,"1":-0.073703681,"2":-0.073703681,"3":-0.073703681,"4":-0.073703681},"house_price":{"0":-0.2416123064,"1":-0.2841806825,"2":-0.259622004,"3":-0.3529449824,"4":-0.3414842657},"pop_density":{"0":-0.1271390651,"1":-0.3105853643,"2":-0.2316607937,"3":-0.3297832328,"4":-0.4599021194},"business_rate":{"0":-0.1662745006,"1":-0.1426329043,"2":-0.1577528867,"3":-0.163560133,"4":-0.1099718326},"noqual_pc":{"0":-0.0251535462,"1":-0.1540641646,"2":-0.0204666924,"3":-0.0515740013,"4":-0.0445135996},"level4qual_pc":{"0":-0.0826103951,"1":-0.1777759951,"2":-0.114263357,"3":-0.1787044751,"4":-0.2709496389},"badhealth_pc":{"0":-0.105481688,"1":-0.1760349683,"2":-0.128215043,"3":-0.1560577648,"4":-0.1760349683}})

palette =['#79BD9A','#69D2E7','#F38630', '#547980','#EDC951']
labels = ['A', 'B', 'C', 'D', 'E']

fig = plt.figure(figsize=(28,20))
position = [[0,0], [0,1], [1,2], [2,0], [2,1]]

axes = []
for row, (letter, col) in enumerate(zip(labels, palette)):
    ax = plt.subplot2grid([4,3], position[row], rowspan=2, colspan=1, **{'polar': True}, sharey=axes[0] if row else None)
    axes.append(ax)
    make_spider( row  = row, title='Group ' + str(letter), color=col, ax=ax)

plt.subplots_adjust(wspace=.4, hspace=.3)
plt.show()

Result

With this solution, sharey has to be set manually. Maybe a cleaner way to do so would be to use ax.get_shared_y_axes().join(*axes) (check here).

Hope it helped.

happyweary
  • 81
  • 2