(fx,fy)=(900,600)
my_dpi=150
fig=plt.figure(figsize=(fx/my_dpi, fy/my_dpi), dpi=my_dpi)
ax = fig.add_subplot(1,1,1)
sns.distplot(a = list(data_dict.values()),) # 输入的是 列表 类型
ax.set_xlabel("Number of arrival train")
ax.set_ylabel("Distribution")
(fx,fy)=(900,600)
my_dpi=150
fig=plt.figure(figsize=(fx/my_dpi, fy/my_dpi), dpi=my_dpi)
ax = fig.add_subplot(1,1,1)
sorted_difs = sorted(difs.items(),key=lambda item:item[1],reverse=True)
names = [name for name,dif in sorted_difs[:10]] # names是横轴显示的文本
dif = [dif for name,dif in sorted_difs[:10]] #dif是数据
rects=plt.bar(range(len(dif)), dif, color='r')
index=list(range(len(dif)))
index=[float(c) for c in index]
plt.xticks(index,names, rotation=90)
plt.xlabel('Stations')# X轴标题
plt.ylabel('abs(departure number - arrival number)')
- plot,一张图里画多条线,且有每条线的legend
plt.rcParams['savefig.dpi'] = 150 #图片像素
plt.rcParams['figure.dpi'] = 150 #分辨率
fig = plt.figure()
count = 0
for name,c in sorted_count:
times = []
for i in range(len(df_list[0])): # 通过循环画多条线
s = df_list[2][i]
if s == name:
time = max(df_list[3][i],df_list[4][i])
times.append(time)
ddd=fenduan(times)
hours = sorted(ddd.keys()) # x
plt.plot(hours,[len(ddd[h]) for h in hours ] ,label=name ) # y
plt.legend(bbox_to_anchor=(0., 1.05, 1., .105), loc=0,
ncol=2, mode="expand", borderaxespad=0.) # 设置legend
plt.xlabel("Hour of day")
plt.ylabel("Number of trains per hour")
count+=1
if count>=4:
break
plt.savefig(file_path+country+'.png', dpi=300) #指定分辨率保存
plt.close()
data = defaultdict(list)
for n in ['Wien Hbf','Wien Meidling','Linz Hbf','St Pölten Hbf']:
data['country'].append('Austria')
data['ratio'].append(froms_dict[n]/tos_dict[n])
data['station'].append(n)
for n in ['Lyon Part-Dieu','Lille Flandres','Paris Montparnasse','Paris Nord']:
data['country'].append('France')
data['ratio'].append(froms_dict[n]/tos_dict[n])
data['station'].append(n)
for n in ['München Hbf','Frankfurt (Main) Hbf','Köln Hbf','Hamburg Hbf']:
data['country'].append('Germany')
data['ratio'].append(froms_dict[n]/tos_dict[n])
data['station'].append(n)
for n in ['Birmingham New Street','Reading','Manchester Piccadilly','Leeds']:
data['country'].append('Great Britain')
data['ratio'].append(froms_dict[n]/tos_dict[n])
data['station'].append(n)
DATA = pd.DataFrame(data = data)
sns.set(style="darkgrid")
sns.set(style="darkgrid")
(fx,fy)=(3000,2000)
my_dpi=300
fig=plt.figure(figsize=(fx/my_dpi, fy/my_dpi), dpi=my_dpi)
ax = fig.add_subplot(1,1,1)
ax = sns.barplot(x="country",
y='ratio',
hue="station",
data=DATA)
网友评论