【python】使⽤matplotlib绘制多个⼦图时出现标题、轴标签等⽂字重叠的
解决
当前代码绘制的图⽚会出现下图中⽂字重叠的情况:
plt.subplot(211)
plt.plot(epochs,loss,'bo',label='Training loss')
plt.plot(epochs,val_loss,'b',label='Validation loss')
plt.title('Training and Validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.subplot(212)
plt.plot(epochs,acc,'ro',label='Training acc')
plt.plot(epochs,val_acc,'r',label='Validation acc')
plt.title('Training and Validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Acc')
plt.legend()
plt.show()
可通过tight_layout()⽅法解决,可根据⾃⼰喜好⾃动移参数:
plt.subplot(211)
plt.plot(epochs,loss,'bo',label='Training loss')
plt.plot(epochs,val_loss,'b',label='Validation loss')
plt.title('Training and Validation loss')
plt.xlabel('Epochs')matplotlib中subplot
plt.ylabel('Loss')
plt.tight_layout()
plt.legend()
plt.subplot(212)
plt.plot(epochs,acc,'ro',label='Training acc')
plt.plot(epochs,val_acc,'r',label='Validation acc')
plt.title('Training and Validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Acc')
plt.tight_layout()
plt.legend()
plt.show()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。