Такое же цветовое определение оттенка для подзаголовков - PullRequest
1 голос
/ 29 мая 2020

Я хочу, чтобы те же определения цветов легенды применялись к 3 частям, поэтому мне нужно только показать легенду в верхней части. Возможно ли это при использовании seabrons "оттенок" или мне нужно использовать matplotlib?

scatterplot with different meaning of colors

def plotverweildauern_with_age(df):

    def rand_float_range(start, end):
        return random.random() * (end - start) + start

    df['years']=df['years'].astype('float64')
    df['age']=df['age'].astype(int)


    sns.set()
    #sharex=True: x-Achse für alle Subplots geteilt
    #fig,ax= plt.subplots(): tuple containing figure and axes object
    fig, ax = plt.subplots(nrows=df['cs'].max(), sharex=True)
    nrows=len(ax)
    ax[df['cs'].max()-1].set_xlabel('Verweildauer in Jahren')

    sns.color_palette("Blues")

    s=[(df["cs"] == t).sum() for t in range(1, df['cs'].max()+1)]
    s.insert(0, 0)
    print(s)


    for i in range(1, df['cs'].max()+1):
        verweildauer_i = df[df['cs'] == i]['years']
        cs_bandwith_i = df[df['cs'] == i]['cs_bandwith']
        age_i = df[df['cs'] == i]['age']

        width=(10*nrows)/3
        height=(7*nrows)/3
        fig.set_size_inches(width,height)
        plt.subplots_adjust(hspace=0)

        sns.scatterplot(x=verweildauer_i, y=cs_bandwith_i-i, hue=age_i, ax=ax[i-1])

        ymin, ymax = ax[i-1].set_ylim()

        if ymax<1:
            ax[i-1].set_ylim(-.5, max(1, ymax))
        else:
            ax[i-1].set_ylim(-1.5, max(1, ymax))

        ax[i-1].set_xlim(-.5, round(df['years'].max(),0)+5)
        ax[i-1].set_ylabel('ZK ' + str(i))
        ax[i-1].set_yticks([])


        handles, labels = ax[i-1].get_legend_handles_labels()
        # create the legend again skipping this first entry
        leg = ax[i-1].legend(handles[1:], labels[1:])

        ax2=ax[i-1]
        ax2 = ax[i-1].twinx()
        ax2.grid(False)
        ax2.set_ylabel("n = {}".format(s[i]), rotation=0, labelpad=25)
        ax2.set_yticks([])
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...