那张图我是用一些技巧来表示我真正想要的,所以它不能很好地显示图例中粉色标记的颜色。
在这张图片中,圆形表示同一参数但针对两个不同的模型;三角形和正方形标记也是如此。我想将指向同一参数的两个圆形标记放在图例的第一行,对于其他两个标记也如此排列在下面的行上。谢谢。
代码:
import matplotlib.pyplot as plt
q1 = [100.0, 60.0, 200.0, 300.0]
NO1 = [0.35799999999999998, 0.33100000000000002, 0.22900000000000001, 0.17799999999999999]
No1 = [0.34599999999999997, 0.29899999999999999, 0.20699999999999999, 0.14999999999999999]
Nb1 = [0.46600000000000003, 0.45600000000000002, 0.27800000000000002, 0.24399999999999999]
q2 = [60.0, 100.0, 200.0, 300.0]
NO2 = [0.44700000000000001, 0.29199999999999998, 0.28299999999999997, 0.253]
No2 = [0.38900000000000001, 0.28499999999999998, 0.311, 0.251]
Nb2 = [0.44, 0.34899999999999998, 0.45900000000000002, 0.39400000000000002]
fig, ax = plt.subplots(figsize = (6,3))
ax.plot(q1, NO1, marker = 'o', markerfacecolor = 'none', markeredgewidth = 1, color = 'gray', linestyle = '', markersize = 8, label = '$N$ in parameter a')
ax.plot(q2, NO2, marker = 'o', markerfacecolor = 'none', markeredgewidth = 1, color = 'palevioletred', linestyle = '', markersize = 8)#, label = '$N$ in parameter a')
ax.plot(q1, No1, marker = '^', markerfacecolor = 'none', markeredgewidth = 1, color = 'gray', linestyle = '', markersize = 8, label = '$N$ in parameter b')
ax.plot(q2, No2, marker = '^', markerfacecolor = 'none', markeredgewidth = 1, color = 'palevioletred', linestyle = '', markersize = 8)#, label = '$N$ in parameter b')
ax.plot(q1, Nb1, marker = 's', markerfacecolor = 'none', markeredgewidth = 1, color = 'gray', linestyle = '', markersize = 8, label = '$N$ in parameter c')
ax.plot(q2, Nb2, marker = 's', markerfacecolor = 'none', markeredgewidth = 1, color = 'palevioletred', linestyle = '', markersize = 8)#, label = '$N$ in parameter c')
#plt.legend(loc='upper right', bbox_to_anchor=(0.945, 1))
plt.xlabel('x')
plt.ylabel('$N$')
plt.xticks([60, 100, 200, 300])
plt.minorticks_on()
plt.tick_params(direction = 'in', bottom = True, top = True, left = True, right = True, which = 'major')
plt.tick_params(direction = 'in', bottom = False, top = False, left = True, right = True, which = 'minor')