Не могу пометить несколько строк sns.catplot () - PullRequest
0 голосов
/ 25 сентября 2018

Вот мой исходный код:

plot = sns.catplot(x='Year',
                   y='Graduation Rate',
                   col='Group',
                   hue='Campus',
                   kind='bar',
                   col_wrap=4,
                   data=mbk_grad.sort_values(['Group', 'Campus']))

for i in np.arange(2):
    for j in np.arange(4):
        ax = plot.facet_axis(i,j) 
        for p in ax.patches:
            if str(p.get_height()) != 'nan':
                ax.text(p.get_x() + 0.06, p.get_height() * .8, '{0:.2f}%'.format(p.get_height()), color='white', rotation='vertical', size='large')

plt.show()

Вывод следующий:

enter image description here

Как получить строкипосле первого помечается как первый ряд?Почему не работает мой вложенный цикл for?

1 Ответ

0 голосов
/ 25 сентября 2018

Если вы посмотрите на plot.axes.shape, вы увидите, что массив осей - это не (2,4), как вы ожидаете, а (8,) одномерный массив.Это потому, что вы используете col_wrap, а не определяете сетку макета.

plot = sns.catplot(x='Year',
                   y='Graduation Rate',
                   col='Group',
                   hue='Campus',
                   kind='bar',
                   col_wrap=4,
                   data=df_sum.sort_values(['Group', 'Campus']))

for i in np.arange(8):
#     for j in np.arange(4):
        ax1 = plot.facet_axis(0,i)
        for p in ax1.patches:
            if str(p.get_height()) != 'nan':
                ax1.text(p.get_x() + 0.06, p.get_height() * .8, '{0:.2f}%'.format(p.get_height()), color='white', rotation='vertical', size='large')

Вывод:

enter image description here

PS,Я посещал Букера Т. Вашингтона (HSEP).Где моя школа HISD здесь?

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