用python画 pareto front

用python画 pareto front

觉得有用的话,欢迎一起讨论相互学习~

我的微博我的github我的B站

2D pf

import os
import matplotlib.pyplot as plt
import numpy as np


def Read_Files(filename):
    X_axis = []  # X
    Y_axis = []  # Y
    with open(filename, 'r') as f:
        for line in f.readlines():
            x = line.split(" ")[0]
            y = line.split(" ")[1]
            X_axis.append(float(x))
            Y_axis.append(float(y))
    f.close()
    return X_axis, Y_axis

def plot_PF(X_axis, Y_axis):
    # 可以通过c 参数设置颜色
    # T = np.arctan2(Y_axis, X_axis)
    # plt.scatter(X_axis, Y_axis, s=2, c=T, alpha=0.5)
    plt.scatter(X_axis, Y_axis, s=20, alpha=0.5)
    plt.savefig(Figname + '.png', dpi=600)
    plt.show()


Filename = './data/CIHS1_hType_circle.pf'
Figname='CIHS1_hType_circle'
X_axis, Y_axis = Read_Files(Filename)
T = np.arctan2(Y_axis, X_axis)
plot_PF(X_axis, Y_axis)

3D pf

import os
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D


def Read_Files(filename):
    X_axis = []  # X
    Y_axis = []  # Y
    Z_axis = []  # Z
    with open(filename, 'r') as f:
        for line in f.readlines():
            # print(line)
            x = line.split("\t")[0]  # 注意,这里不是使用空格,而是使用Tab制表符进行分割
            # print(x)
            y = line.split("\t")[1]
            # print(y)
            z = line.split("\t")[2]
            # print(z)
            X_axis.append(float(x))
            Y_axis.append(float(y))
            Z_axis.append(float(z))
    f.close()
    return X_axis, Y_axis, Z_axis


def plot_PF(X_axis, Y_axis, Z_axis):

    ax = plt.figure().add_subplot(111, projection='3d')
    # c 设置颜色,alpha设置透明度,s设置点的大小
    ax.scatter(X_axis, Y_axis, Z_axis, c='b', alpha=0.5, s=3)

    plt.savefig(Figname + '.png', dpi=600)
    plt.show()


Filename = './data/hType_sphere.pf'
Figname = 'hType_sphere'
X_axis, Y_axis, Z_axis = Read_Files(Filename)
plot_PF(X_axis, Y_axis, Z_axis)

Note

  • 如果使用Pycharm的图片展示,则画出来的3D图形是不能够旋转的,此时必须关闭pycharm的"Show plots in tool windows"

https://blog.csdn.net/u013555719/article/details/83896790

  • 以下是使用pycharm画出的图形
  1. “File—>Settings”,打开Settings窗口。
  2. 找到“Python Scientific”,去除右边候选框中的勾号。
  • 用上述步骤后使用python原生画图工具显示的图形
posted @ 2019-08-08 21:26  WUST许志伟  阅读(1958)  评论(0编辑  收藏  举报