user2543622
user2543622

Reputation: 6756

python plotting change background color and line color

This link has a tutorial that shows how to plot different metrics for test and training data by epochs. Please check the output of plot_metrics(baseline_history)

I only have two metrics to print I copied the plotting part and need help with below

  1. How to change color of test line to red? I tried plt.plot(history.epoch, history.history['val_'+metric], color=colors['r'], linestyle="--", label='Val') But got the error TypeError: list indices must be integers or slices, not str

  2. how to ensure the plain background. For some reason I am getting grey color background with white lines

my code and output below

#plotting
def plot_metrics(history):
  metrics =  ['loss','acc']
  for n, metric in enumerate(metrics):
    name = metric.replace("_"," ").capitalize()
    plt.subplot(2,2,n+1)
    plt.plot(history.epoch,  history.history[metric], color=colors[0], label='Train')
    plt.plot(history.epoch, history.history['val_'+metric],
             color=colors[9], linestyle="--", label='Val')
    plt.xlabel('Epoch')
    plt.ylabel(name)
    if metric == 'loss':
      plt.ylim([0, plt.ylim()[1]])
    elif metric == 'auc':
      plt.ylim([0.8,1])
    else:
      plt.ylim([0,1])

    plt.legend()

import matplotlib.pyplot as plt
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = (20, 12)
plot_metrics(final_model)#where abcde is fit call

enter image description here

Upvotes: 0

Views: 920

Answers (1)

ganesh marella
ganesh marella

Reputation: 56

  1. You can simply try adding the color parameter. Usage: plt.plot([1,2,3,4,5,6], color='red')

  2. You can use grid(False) to remove the grid. usage: plt.grid(False)

Upvotes: 1

Related Questions