先导包(必须安装了numpy 、pandas 和matplotlib才能导包):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
核心代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option("max_columns",None)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
months=["5月","6月","7月","8月"]
x=np.arange(4)
weights=[140,130.125,110]
weights2=[140,135.145,150]
plt.plot(weights,label="老王")
plt.plot(weights2,label="小王")
plt.xticks(x,months)
plt.xlabel("月份")
plt.ylabel("体重")
plt.title("减肥奋斗史")
plt.legend()#显示折线图例
plt.show()