Построение нескольких графиков с использованием цикла for - PullRequest
0 голосов
/ 16 апреля 2020

У меня всего 35 предметов, и я пытаюсь составить отдельный график для каждого, использующего для l oop, но мой код дает мне один плотный график со всеми предметами.

all_subnames = final['sub'].unique() # this shows all the subjects 1-35

[for i in all_subnames:
    print(i)
    subs = final\[final\['sub'\]== i\]
    sns.lineplot(x = subs.index.values,y = subs\['RT'\])][1]

Ответы [ 2 ]

0 голосов
/ 16 апреля 2020

Убедитесь, что вы открываете новую фигуру для каждого сюжета:

import matplotlib
import matplotlib.pyplot as plt
import seaborn

all_subnames = final['sub'].unique() # this shows all the subjects 1-35

for i in all_subnames:
    print(i)
    subs = final\[final\['sub'\]== i\]

    # Creates a new figure for the plot of the subject
    plt.figure()
    sns.lineplot(x = subs.index.values,y = subs\['RT'\])][1]
0 голосов
/ 16 апреля 2020

Вы хотите создать новую фигуру и ось для каждой итерации в течение l oop. Это один из способов сделать это.

import seaborn as sns

## made up date with 10 rows, 5 columns
y = np.random.randint(low=1,high=10,size=(10,5))

# iterate over the data
for item in range(y.shape[1]):

    # create a new figure and axis object  
    fig, ax = plt.subplots()

    # give this axis to seaborn so that it can plot in each iteration
    sns.lineplot(np.arange(y.shape[0]) ,y[:,item], ax = ax)
...