BoxPlot.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:SecuML 作者: ANSSI-FR 项目源码 文件源码
def display(self, output_filename):
        fig, (ax) = plt.subplots(1, 1)
        data   = [d.values for d in self.datasets]
        labels = [d.label for d in self.datasets]
        bp = ax.boxplot(data, labels = labels, notch = 0, sym = '+', vert = '1', whis = 1.5)
        plt.setp(bp['boxes'], color='black')
        plt.setp(bp['whiskers'], color='black')
        plt.setp(bp['fliers'], color='black', marker='+')
        for i in range(len(self.datasets)):
            box = bp['boxes'][i]
            box_x = []
            box_y = []
            for j in range(5):
                box_x.append(box.get_xdata()[j])
                box_y.append(box.get_ydata()[j])
            box_coords = list(zip(box_x, box_y))
            box_polygon = Polygon(box_coords, facecolor = self.datasets[i].color)
            ax.add_patch(box_polygon)
        if self.title is not None:
            ax.set_title(self.title)
        x_min = np.amin([np.amin(d.values) for d in self.datasets])
        x_max = np.amax([np.amax(d.values) for d in self.datasets])
        ax.set_ylim(x_min - 0.05*(x_max - x_min), x_max + 0.05*(x_max - x_min))
        fig.savefig(output_filename)
        plt.close(fig)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号