Вставить небольшой радарчарт в сюжет matplotlib - PullRequest
0 голосов
/ 27 октября 2018

Прямо сейчас я могу создать радарчарт следующим образом. Обратите внимание, что я сделал эту функцию просто для того, чтобы я мог более просто вставить функцию в мою большую диаграмму рассеяния.

Диаграмма радара

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 

Затем я хочу поместить эту фигуру в правом нижнем углу моего графика рассеяния, который у меня есть в другом месте. Эта другая статья не дает мне никакого способа сделать это, так как мой сюжет круговой. Любая помощь будет отличной!

Когда я звоню radarChart('someones name'), я получаю

enter image description here

Мне бы очень хотелось, чтобы не нужно было сначала сохранять его как изображение, а затем помещать в график.

1 Ответ

0 голосов
/ 28 октября 2018

Я не уверен, какой у вас желаемый результат.Вы всегда должны предоставить Минимальный, Полный и Проверяемый пример .Кроме того, я не знаю, почему полярный график будет отличаться от любого другого графика для создания вставки:

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()

Пример вывода:
enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...