需求
这里想把数据组合到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')
这里不添加结果图, 请自行脑补。
网友评论