import numpy as np
import matplotlib
matplotlib.rcParams['font.family'] = 'Times New Roman'
matplotlib.rcParams['mathtext.default'] = 'regular'
import matplotlib.pyplot as plt
# from mpl_toolkits.mplot3d import Axes3D
# 设置在jupyter中显示大小
import pylab
pylab.rcParams['figure.figsize'] = (15.0, 8.0)
# plt.figure(facecolor='blue', # 图表区的背景色
# edgecolor='black') # 图表区的边框线颜色
# ax.spines['top'].set_visible(False) #去掉上边框
# ax.spines['bottom'].set_visible(False) #去掉下边框
# ax.spines['left'].set_visible(False) #去掉左边框
# ax.spines['right'].set_visible(False) #去掉右边框
COLOR = ["cornflowerblue", "mediumturquoise", "mediumpurple", "chocolate", "lightcoral"]
# COLOR = [ "mediumpurple", "chocolate", "plum"]
# lambda1 = lambda2 = [10 ** x for x in range(-2, 3)]
lambda1 = [0.0, 0.2, 0.5, 0.8, 1.0]
lambda2 = [2, 4, 6, 8, 10]
# x, y: position
x = list(range(len(lambda1)))
y = list(range(len(lambda2)))
x_tickets = [str(_x) for _x in lambda1]
y_tickets = [str(_x) for _x in lambda2]
# acc = np.random.rand(len(x), len(y))
# acc = np.arange(len(x) * len(y)).reshape(len(x), len(y)) + 1
# acc = acc / acc.max()
acc = np.array([77.3, 76.6, 76.4, 75.5, 75.7,
70.0, 70.0, 70.0, 70.0, 70.0,
77.2, 76.8, 75.5, 75.7, 75.0,
70.0, 70.0, 70.0, 70.0, 70.0,
77.5, 77.8, 77.5, 77.0, 77.0])
# xx, yy = np.meshgrid(x, y) # 这样两根轴会反过来
yy, xx = np.meshgrid(x, y) # 要反过来,见 [9]
print(xx)
# print(yy)
color_list = []
for i in range(len(y)):
c = COLOR[i]
color_list.append([c] * len(x))
color_list = np.asarray(color_list)
print(color_list)
xx_flat, yy_flat, acc_flat, color_flat = \
xx.ravel(), yy.ravel(), acc.ravel(), color_list.ravel()
print(xx_flat)
print(yy_flat)
# print(color_flat)
# fig, ax = plt.subplots(projection="3d")
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.bar3d(xx_flat - 0.35, yy_flat - 0.35, 70, 0.7, 0.7, acc_flat-70,
color=color_flat, # 颜色
edgecolor="lightgrey", # 黑色描边
shade=False, # 加阴影
alpha=0.6) # 透明度 https://www.cnblogs.com/always-fight/p/9707727.html
# for x, y, z in zip(xx_flat - 0.35,yy_flat - 0.35, acc_flat):
# plt.text(x+0.05,y+0.05,'%.2f' %y, ha='center',va='bottom')
for i in range(len(xx_flat)):
ax.text((xx_flat - 0.)[i],(yy_flat - 0.)[i],(acc_flat)[i], (acc_flat)[i])
ax.set_xlabel(r"$\gamma$")
ax.set_ylabel(r"$num$")
ax.set_zlabel("GZSL_H")
# 座标轴范围
# ax.set_zlim((0, 80))
ax.set_zlim(70, 80) # 有效
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.grid(False)
ax.set_xticks(x)
ax.set_xticklabels(x_tickets)
ax.set_yticks(y)
ax.set_yticklabels(y_tickets)
plt.show()
# 保存
plt.tight_layout()
fig.savefig("img_name.png", bbox_inches='tight', pad_inches=0, dpi=800)
# plt.close(fig)
绘制折线图
# 绘制温度超参数折线图
import numpy as np
import matplotlib.pyplot as plt
import math
import matplotlib
matplotlib.rcParams['font.family'] = 'Times New Roman'
matplotlib.rcParams['mathtext.default'] = 'regular'
import pylab
pylab.rcParams['figure.figsize'] = (10.0, 7.0)
plt.rc('text', usetex=True)
# AWA2
t = [math.log(0.2, 2), math.log(0.5,2), math.log(1, 2), math.log(2, 2), math.log(5, 2)]
# print(t)
T = [79.5, 79.3, 79.0, 79.0, 78.9]
U = [72.6, 72.0, 72.6, 73.0, 72.5]
S = [83.2, 84.7, 84.6, 82.0, 84.8]
H = [77.5, 77.8, 78.1, 77.3, 78.2]
# https://blog.csdn.net/sinat_36219858/article/details/79800460
l1=plt.plot(t, T,'r', marker='o', linestyle='-', markersize=8, linewidth=2, label='ZSL\_T')
l2=plt.plot(t, U,'g', marker='s', linestyle='-', markersize=8, linewidth=2, label='GZSL\_U')
l3=plt.plot(t, S,'b', marker='^', linestyle='-', markersize=8, linewidth=2, label='GZSL\_S')
l4=plt.plot(t, H,'y', marker='v', linestyle='-', markersize=8, linewidth=2, label='GZSL\_H')
# plt.plot(t,T,'ro-',t, U,'g+-', t,S,'b^-', t,H,'^-')
plt.title('')
plt.xlim(-2.5, 2.5)
plt.ylim(60, 90)
# plt.ylabel(r'\bf{phase field} $\phi$')
plt.xlabel(r'$log{_2}{t}$')
plt.ylabel('Accuracy (\%)')
plt.legend()
# plt.show()
plt.savefig("AWA2_Temp_hyp.png", bbox_inches='tight', pad_inches=0, dpi=1000)