Python实现可视化(二)–label字体大小调整、图例设置
python实现可视化
基于python画图实现图例和XY轴label字体设置
Talk is Cheap. Show me the Code
// 定义画图函数:传参为多个时段的dataframe
def func_plot_qk(df1, df2, df3, df4, df5):
// 初始图片,s=2表示scatter的大小(常规设置),x轴为dataframe中的‘density’列,y轴为dataframe中的‘volume’列
ax = df5.plot(kind='scatter', x='density', y='volume', color='DarkOrange', s=2, label='其他时段')
df4.plot(kind='scatter', x='density', y='volume', color='g', s=2, label='夜间,23:00-06:00', ax=ax)
df3.plot(kind='scatter', x='density', y='volume', color='r', s=2, label='晚高峰,17:00-19:00', ax=ax)
df2.plot(kind='scatter', x='density', y='volume', color='y', s=2, label='下午高峰,13:30-15:00', ax=ax)
df1.plot(kind='scatter', x='density', y='volume', color='b', s=2, label='早高峰,07:00-09:00', ax=ax)
// fontsize控制XY坐标轴label的大小,同样适用title
plt.xlabel('平均密度:车/公里车道', fontsize=14)
plt.ylabel('流量:车/小时/车道', fontsize=14)
plt.title('流量-密度图', fontsize=14)
// 控制图例的形状大小:fontsize控制图例字体大小,markerscale控制scatters形状大小,scatterpoints控制scatters的数量
plt.legend(fontsize=14, markerscale=2., scatterpoints=1)
plt.show()
return True
// 调用函数
func_plot_qk(df_morning,df_afternoon,df_night,df_midnight, df_otp)
结果为
PS:上图为交通流理论中经典Q-K图,即流量-密度图。