一列数据:
import pandas as pd
import matplotlib
matplotlib.rcParams['axes.unicode_minus']=False
from matplotlib import pyplot as plt
excelFile = r'C:/Users/admin/Desktop/2019.10.05/折线图/一条/pclsum.xlsx'
df=pd.DataFrame(pd.read_excel(excelFile))
x=list(df['战队名'])
y=list(df['回合数'])
fig = plt.figure(figsize=(10,4))
ax = fig.add_subplot(1, 1, 1)
ticks = ax.set_xticks(range(0,16))#设定x轴有16个标签
ax.plot(y,'ko--')
labels = ax.set_xticklabels(x,fontsize='small') #旋转30度,这里横坐标可以是d:list,也可以是c:series
plt.grid(True)
plt.show()
结果:
4AM_ZGG01 | 4AM_forever | 4AM_weless | 4AM_xlxuu | |
周一 | 0 | 468 | 90 | 265 |
周二 | 159 | 307 | 18 | 82 |
周三 | 26 | 0 | 268 | 134 |
周四 | 168 | 0 | 97 | 103 |
周五 | 45 | 624 | 365 | 160 |
import pandas as pd
import seaborn as sns
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus']=False
from matplotlib import pyplot as plt
excelFile = r'C:/Users/admin/Desktop/2019.10.05/折线图/多条/训练赛.xlsx'
df=pd.DataFrame(pd.read_excel(excelFile))
fig = plt.figure()
sns.set( palette="muted",color_codes=True)
ax = fig.add_subplot(1, 1, 1)
# print(df)(不是这种形式的话,可以用excel进行转置)
ticks = ax.set_xticks(range(0,5))#设定x轴有6个标签
x=['周一','周二','周三','周四','周五']
labels = ax.set_xticklabels(x,rotation=30, fontsize='small')
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
ax.plot(df['4AM_ZGG01'],'k', label='4AM_ZGG01')
ax.plot(df['4AM_forever'],'b', label='4AM_forever')
ax.plot(df['4AM_weless'],'g', label='4AM_weless')
ax.plot(df['4AM_xlxuu'],'r', label='4AM_xlxuu')
ax.legend(loc='best')#自动生成图列,loc是位置参数,best也可以用plt.legend
plt.grid(True)
plt.show()
plt.savefig("4am.jpg")
结果: