[英]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)
请检查plot_metrics(baseline_history)
的输出
I only have two metrics to print I copied the plotting part and need help with below我只有两个指标要打印,我复制了绘图部分,需要以下帮助
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
我试过plt.plot(history.epoch, history.history['val_'+metric], color=colors['r'], linestyle="--", label='Val')
但是得到了错误TypeError: list indices must be integers or slices, not str
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
You can simply try adding the color parameter.您可以简单地尝试添加颜色参数。 Usage: plt.plot([1,2,3,4,5,6], color='red')用法:plt.plot([1,2,3,4,5,6], color='red')
You can use grid(False) to remove the grid.您可以使用 grid(False) 删除网格。 usage: plt.grid(False)用法:plt.grid(False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.