简体   繁体   English

plot 重叠使用 matplotlib

[英]plot overlaps using matplotlib

I am learning matplotlib.我正在学习 matplotlib。

I am trying to plot two below plots in a single plot using matplotlib.我正在尝试使用 matplotlib 在单个 plot 中的 plot 两个下面的图。

在此处输入图像描述

在此处输入图像描述

But it overlaps.但它重叠。 在此处输入图像描述

Here is my code.这是我的代码。

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

train_error = [0.26462888486225206, 0.26462383329393313, 0.2628674962680674, 0.2553700231555298, 0.17473717177688022, 0.14773444580059242, 0.1468299949185866, 0.1468235689407127, 0.1439370366766204]
test_error = [0.8438224756653776, 0.8442034650577578, 1.018608707726192, 4.853704454584892, 123.69312582226338, 798.4569874115062, 3205.5264038946007, 9972.587330411312, 10787335.618580218]

plt.plot(train_error)
plt.plot(test_error)
plt.show()

Where am i doing wrong?我在哪里做错了? Can anyone please guide / help ?谁能指导/帮助

Use the subplot使用子图

Go check https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html Go 检查https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.ZFC35FDC70D5FC69D269883A822C7A5

plt.subplot(1,2,1)
plt.plot(train_error)
plt.subplot(1,2,2)
plt.plot(test_error)

in plt.subplot(a,b,x) you have a,b that represents the number of (row and column) you want vertically and horizontally and x the index of the subplot selected counting from left to right and top to bottom.在 plt.subplot(a,b,x) 你有 a,b 代表你想要垂直和水平的(行和列)的数量和 x 选择的子图的索引从左到右和从上到下计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM