美文网首页程序员
pandas DataFrame数据画图并通过matplotli

pandas DataFrame数据画图并通过matplotli

作者: 张王李刘赵孙杨 | 来源:发表于2019-01-03 11:46 被阅读109次

需求

这里想把数据组合到pandas的dataframe中,然后画一个条形图,通过matplotlib保存下来。

代码

155     #3.2 bar
156     if pre_path1 is not None:
157         index = [filename[:-4] for filename in file_names]
158         fig = plt.figure() # create a figure
159         fig.suptitle('dice and haus in test-set')
160 
161         ax1 = fig.add_subplot(121) # add an axis
162         ax1.set_title('dice')
163         dice_info = {pre_path:dice_list, pre_path1:dice_list1}
164         df = pd.DataFrame(dice_info, index=index)
165         df.plot(ax=ax1, kind='bar') # plot data into axis
166 
167         ax2 = fig.add_subplot(122)
168         ax2.set_title('haus')
169         haus_info = {pre_path:haus_list, pre_path1:haus_list1}
170         df = pd.DataFrame(haus_info, index=index)
171         df.plot(ax=ax2, kind='bar')
172 
173         plt.tight_layout()
174         fig.savefig(args.save_path[:-3]+'_bar.png')

这里不添加结果图, 请自行脑补。

参考

  1. Matplotlib figure title
  2. pandas.DataFrame.plot.bar
  3. Pandas Bar Plot using Subplots

相关文章

网友评论

    本文标题:pandas DataFrame数据画图并通过matplotli

    本文链接:https://www.haomeiwen.com/subject/cikfrqtx.html