Как отобразить значения второй оси Y в matplotlib? - PullRequest
0 голосов
/ 05 июля 2018

Мне нравится отображать значения по второй оси Y (справа по вертикали) в matplotlib. Мой код выглядит следующим образом.

def main(files):
    plt.style.use('ggplot')
    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()
    ax1.set_xlabel('iteration')
    losslabel = ax1.set_ylabel('loss')
    losslabel.set_color("red")
    accuracylabel = ax2.set_ylabel('accuracy %')
    accuracylabel.set_color("green")
    disp_results(fig, ax1, ax2, loss_iterations, losses, accuracy_iterations, accuracies, accuracies_iteration_checkpoints_ind, fileName, color_ind=i)
    plt.show()


def disp_results(fig, ax1, ax2, loss_iterations, losses, accuracy_iterations, accuracies, accuracies_iteration_checkpoints_ind, fileName, color_ind=0):
    colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
    acrIterations =[]
    top_acrs={}
    if accuracies.size:
        if  accuracies.size>4:
            top_n = 4
        else:
            top_n = accuracies.size -1      
        temp = np.argpartition(-accuracies, top_n)
        result_indexces = temp[:top_n]
        temp = np.partition(-accuracies, top_n)
        result = -temp[:top_n]
        for acr in result_indexces:
            acrIterations.append(accuracy_iterations[acr])
            top_acrs[str(accuracy_iterations[acr])]=str(accuracies[acr])

        sorted_top4 = sorted(top_acrs.items(), key=operator.itemgetter(1))
        maxAcc = np.amax(accuracies, axis=0)
        iterIndx = np.argmax(accuracies)
        maxAccIter = accuracy_iterations[-1]
        maxIter =   accuracy_iterations[-1]
        consoleInfo = format('\n[%s]:Test accuracy Vs Train loss [from 0 to %s ] = [Iteration %s]: %s ' %(fileName,maxIter,maxAccIter ,maxAcc))
        plotTitle = format('Test accuracy Vs Train loss(%s) [Iteration %s]: %s ' % (fileName,maxAccIter, maxAcc))
        print (consoleInfo)

        print ('Top 4 accuracies:'+str(sorted_top4))        
        plt.title(plotTitle)
    ax1.plot(loss_iterations, losses, colors['red'])
    ax2.plot(accuracy_iterations, accuracies, colors['green'], label=str(fileName))
    ax2.plot(accuracy_iterations[accuracies_iteration_checkpoints_ind], accuracies[accuracies_iteration_checkpoints_ind], 'o', colors['red'])

График в порядке, только значения правой вертикальной оси не отображаются. Участок здесь .

enter image description here

Код Python и файлы журналов здесь и здесь .

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