要从 matplotlib 中的 .CSV 文件制作多线图,我们可以采取以下步骤 -
设置图形大小并调整子图之间和周围的填充。
创建列列表以从 .CSV 文件中获取数据。确保名称与 .CSV 文件中使用的列名匹配。
从 .CSV 文件中读取数据。
使用方法绘制线条。df.plot()
要显示图形,请使用show()方法。
import pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Make a list of columns columns = ['mpg', 'displ', 'hp', 'weight'] # Read a CSV file df = pd.read_csv("auto-mpg.csv", usecols=columns) # Plot the lines df.plot() plt.show()输出结果
它将产生以下输出