sparksql_可视化组分布_histogram
可参考:
https://blog.csdn.net/weixin_39599711/article/details/79072691
# 如果数据是几百万行,第二种方法显然不可取。因此需要先聚合数据。
hists = fraud_df.select('balance').rdd.flatMap(lambda row: row).histogram(20)
To plot the histogram you can simply call the matplotlib like below.
# 绘图:
data = {
'bins': hists[0][:-1],
'freq': hists[1]
}
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(1, 1, 1)
ax.bar(data['bins'], data['freq'], width=2000)
ax.set_title('Histogram of \'balance\'')
plt.savefig('B05793_05_22.png', dpi=300)