0

Right now I can create a radarchart as follows. Note that I made it a function just so that I can simply insert the function into my larger scatterplot more cleanly.

Radar Chart

def radarChart(PlayerLastName):
    playerdf = dg.loc[dg['Player Name'] == name].index.tolist()[0]
    #print(playerdf)

    labels=np.array(['SOG', 'SH', 'G', 'A'])
    stats=dg.loc[playerdf,labels].values
    #print(stats)

    # Set the angle of polar axis. 
    # And here we need to use the np.concatenate to draw a closed plot in radar chart.
    angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False)
    # close the plot
    stats=np.concatenate((stats,[stats[0]]))
    angles=np.concatenate((angles,[angles[0]]))

    fig = plt.figure()
    ax = fig.add_subplot(111, polar=True)
    ax.plot(angles, stats, 'o-', linewidth=1)
    ax.fill(angles, stats, alpha=0.3)
    ax.set_thetagrids(angles * 180/np.pi, labels)
    #plt.title(PlayerLastName + ' vs. ' + namegame)
    ax.grid(True)

    return 

I then want to put this figure in the bottom right of my scatter plot I have elsewhere. This other article does not provide me with any way to do this since my plot is circular. Any help would be great!

When I call radarChart('someones name') I get

enter image description here

I would really like to not have to save it as an image first and then put it in the plot.

bbd108
  • 958
  • 2
  • 10
  • 26

1 Answers1

0

I am not sure, what your desired output is. You should always provide a Minimal, Complete, and Verifiable example. Apart from this, I don't know, why a polar plot would be different from any other plot to create an inset:

import matplotlib.pyplot as plt
import numpy as np

#function for the polar plot
def radarChart(Player = "SOG", left = .3, bottom = .6, width = .2, height = .2):
    #labels and positions
    labels = np.array(['SOG', 'SH', 'G', 'A'])
    angles = np.linspace(0, 360, len(labels), endpoint = False)
    #inset position
    ax = plt.axes([left, bottom, width, height], facecolor = "lightblue", polar = True)
    #label polar chart
    ax.set_thetagrids(angles, labels)
    #polar chart title
    plt.title(Player, loc = "left")

    return ax

#main figure
x = np.linspace (-3, 1, 1000)
y = 2 * np.exp(3 - x) - 1
plt.plot(x, y)
plt.xlabel("x values")
plt.ylabel("y values")
plt.title("figure with polar insets")

#inset 1
ax = radarChart(Player = "A")
plt.scatter(x[::50], y[::50])

#inset 2
ax = radarChart(left = .6, bottom = .4, width = .2, height = .2)
plt.plot(x, y)

plt.show()

Sample output:
enter image description here

Mr. T
  • 11,960
  • 10
  • 32
  • 54