如何使用Python创建超体积和曲面实现图(用于2个目标)?
有人知道如何使用Python创建下面这样的绘图吗?我想知道如何绘制直线和阴影区域 超体积+表面达到图:如何使用Python创建超体积和曲面实现图(用于2个目标)?,python,plot,graphics,Python,Plot,Graphics,有人知道如何使用Python创建下面这样的绘图吗?我想知道如何绘制直线和阴影区域 超体积+表面达到图: hypervolume和surface Acquisition都被用作多目标优化算法的性能指标。最后我自己设法解决了这个问题。以下是我的方法(比较多目标算法在特定更改前后的性能): 这将产生以下结果(这表明“变化”产生了负面影响) 欢迎任何建设性的批评 最后我自己设法解决了这个问题。以下是我的方法(比较多目标算法在特定更改前后的性能): 这将产生以下结果(这表明“变化”产生了负面影响) 欢迎任
hypervolume和surface Acquisition都被用作多目标优化算法的性能指标。最后我自己设法解决了这个问题。以下是我的方法(比较多目标算法在特定更改前后的性能): 这将产生以下结果(这表明“变化”产生了负面影响)
欢迎任何建设性的批评 最后我自己设法解决了这个问题。以下是我的方法(比较多目标算法在特定更改前后的性能): 这将产生以下结果(这表明“变化”产生了负面影响)
欢迎任何建设性的批评 试试下面的功能 它产生了以下结果:
将numpy导入为np
将matplotlib.pyplot作为plt导入
def绘图超卷(x、y、参考点):
x=np.数组(x)
y=np.数组(y)
#把x和y压缩成一个小数组
坐标=np.数组(已排序(zip(x,y)))
#空帕累托集
帕累托集合=np.full(坐标.shape,np.inf)
i=0
对于坐标中的点:
如果i==0:
帕累托集[i]=点
i+=1
elif点[1]
尝试下面的功能
它产生了以下结果:
将numpy导入为np
将matplotlib.pyplot作为plt导入
def绘图超卷(x、y、参考点):
x=np.数组(x)
y=np.数组(y)
#把x和y压缩成一个小数组
坐标=np.数组(已排序(zip(x,y)))
#空帕累托集
帕累托集合=np.full(坐标.shape,np.inf)
i=0
对于坐标中的点:
如果i==0:
帕累托集[i]=点
import matplotlib.pyplot as plt
cases = ['before', 'after']
objectives = ['obj1', 'obj2']
colors = ['green', 'red']
data = {case : pd.read_csv(case +'.csv', index_col=False) for case in cases}
fig, axes = plt.subplots()
for j, case in enumerate(cases):
obj1 = sorted(data[case][objectives[0]].values)
obj2 = sorted(data[case][objectives[1]].values)
#Plot the first two pts outside the loop to display the label
axes.plot([obj1[0], obj1[0]], [obj2[0], obj2[1]],
color=colors[j],
label=case)
axes.plot([obj1[0], obj1[1]], [obj2[1], obj2[1]],
color=colors[j])
for i in range(2, len(obj1)):
axes.plot([obj1[i - 1], obj1[i - 1]], [obj2[i - 1], obj2[i]],
color=colors[j])
axes.plot([obj1[i - 1], obj1[i]], [obj2[i], obj2[i]],
color=colors[j])
axes.set_xlabel(objectives[0])
axes.set_ylabel(objectives[1])
axes.plot(nadir_r[0],
nadir_r[1],
'*',
label='nadir')
axes.plot(ideal_r[0],
ideal_r[1],
'x',
label='ideal')
plt.xlim(nadir_r[0], ideal_r[0])
plt.ylim(ideal_r[1], nadir_r[1])
axes.legend(loc='best')
import numpy as np
import matplotlib.pyplot as plt
def plot_hyper_volume(x, y, reference_point):
x = np.array(x)
y = np.array(y)
# Zip x and y into a numpy ndarray
coordinates = np.array(sorted(zip(x, y)))
# Empty pareto set
pareto_set = np.full(coordinates.shape, np.inf)
i = 0
for point in coordinates:
if i == 0:
pareto_set[i] = point
i += 1
elif point[1] < pareto_set[:, 1].min():
pareto_set[i] = point
i += 1
# Get rid of unused spaces
pareto_set = pareto_set[:i + 1, :]
# Add reference point to the pareto set
pareto_set[i] = reference_point
# These points will define the path to be plotted and filled
x_path_of_points = []
y_path_of_points = []
for index, point in enumerate(pareto_set):
if index < i - 1:
plt.plot([point[0], point[0]], [point[1], pareto_set[index + 1][1]], marker='o', markersize=4, c='#4270b6',
mfc='black', mec='black')
plt.plot([point[0], pareto_set[index + 1][0]], [pareto_set[index + 1][1], pareto_set[index + 1][1]],
marker='o', markersize=4, c='#4270b6', mfc='black', mec='black')
x_path_of_points += [point[0], point[0], pareto_set[index + 1][0]]
y_path_of_points += [point[1], pareto_set[index + 1][1], pareto_set[index + 1][1]]
# Link 1 to Reference Point
plt.plot([pareto_set[0][0], reference_point[0]], [pareto_set[0][1], reference_point[1]], marker='o', markersize=4,
c='#4270b6', mfc='black', mec='black')
# Link 2 to Reference Point
plt.plot([pareto_set[-1][0], reference_point[0]], [pareto_set[-2][1], reference_point[1]], marker='o', markersize=4,
c='#4270b6', mfc='black', mec='black')
# Highlight the Reference Point
plt.plot(reference_point[0], reference_point[1], 'o', color='red', markersize=8)
# Fill the area between the Pareto set and Ref y
plt.fill_betweenx(y_path_of_points, x_path_of_points, max(x_path_of_points) * np.ones(len(x_path_of_points)),
color='#dfeaff', alpha=1)
plt.xlabel(r"$f_{\mathrm{1}}(x)$", fontsize=18)
plt.ylabel(r"$f_{\mathrm{2}}(x)$", fontsize=18)
plt.tight_layout()
plt.show()
x = [3.237887527110896, 3.253687689154591, 2.6652460044515833, 4.457925635186012, 3.2080041315472436,
3.196941509672105, 3.1489091846746784, 3.3727329491336504, 3.2980773800599184, 3.330938419470396,
3.0504985412687606, 3.9698249482752517, 3.1229599570521005, 3.1278496698518365, 3.3410372676796367,
3.267339581661665, 3.1531143837247226, 3.13276172330508, 3.2136444869087857, 3.123114522218978,
2.8975316624890177, 3.855654194881272, 2.982889291813081, 4.001132534228973, 3.222172022988187,
3.2918121975763426, 3.119437722697402, 3.1915652020314855, 3.228511161109151, 3.410632525789594,
3.303983909300615, 3.23152665486737, 3.12295981695552, 3.123114522218978, 3.2134999576177727, 3.3042667387038263,
3.379569640868453, 3.2597834943233255, 3.2365405477218783, 3.2911687133624765, 3.1835704013006616,
3.1363291696973903, 3.1422814239459718, 3.1202417240558282, 3.1311337111075535, 3.630375287962374,
3.181708872213033, 3.2993090610457774, 3.130988434129236, 3.12295981695552]
y = [3.5471650938674886, 3.446106995806536, 4.203717903464938, 2.53919767967234, 3.550936505497275, 3.553107544090778,
3.648527616343033, 3.3076630507066875, 3.3498580074252184, 3.320019542824605, 3.752735495100324,
2.853419245618656, 3.71421025754152, 3.709380479951111, 3.307305266656153, 3.5468875845765266, 3.7140635724580386,
3.6981877554394647, 3.6799057516573295, 3.714041693123077, 3.831023904192475, 2.873083146950819,
4.195177914971685, 2.8302302203075165, 3.4285829711629616, 3.3624540805968035, 3.7156683374998387,
3.5623734317415163, 3.627757758118092, 3.2755855532302336, 3.318743777730811, 3.7213811168338164,
3.714210410334474, 3.714041693123077, 3.45357840149967, 3.6337156456167627, 3.270784928858892, 3.400665041601096,
3.5451613263457076, 3.357372990242752, 3.5705676117602683, 3.6930983812240736, 3.687202266647831,
3.717332517575802, 3.7061199284167357, 3.1769420991200708, 3.492240477791187, 3.512518414215774,
3.7040103293332383, 3.714210410334474]
ref = [max(x), max(y)]
plot_hyper_volume(x=x, y=y, reference_point=ref)