[英]python plotting change background color and line color
此鏈接有一個教程,展示了如何按時期為測試和訓練數據繪制不同的指標。 請檢查plot_metrics(baseline_history)
的輸出
我只有兩個指標要打印,我復制了繪圖部分,需要以下幫助
如何將測試線的顏色更改為紅色? 我試過plt.plot(history.epoch, history.history['val_'+metric], color=colors['r'], linestyle="--", label='Val')
但是得到了錯誤TypeError: list indices must be integers or slices, not str
如何保證純背景。 出於某種原因,我得到了帶有白線的灰色背景
我的代碼和輸出如下
#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
您可以簡單地嘗試添加顏色參數。 用法:plt.plot([1,2,3,4,5,6], color='red')
您可以使用 grid(False) 刪除網格。 用法:plt.grid(False)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.