搞mobile一直注重的理论研究,直到被顶刊退稿,被各种reviewer说实验不充分,才意识到实验的重要性,总结一下常用的几种图吧(blog做我笔记本)
普通折线图
效果图:
import matplotlib.pyplot as plt
import numpy as np
# 优雅地创建Figure和Axes
fig, ax = plt.subplots()
# 优雅地添加基础类对象
x = [1,2,3,4]
MAX = 500; MIN = 0#数据的最大最小值
y1 = [3639.3999062781245, 3411.820969547731, 3134.381409499655, 3108.8418180761682]
y2 = [1554.4144202106154, 2163.045623161998, 2158.4135591973645, 2177.875018596146]
y3 = [2393.778532894126, 2642.3848040954695, 2774.447707450162, 2836.635174277972]
y4 = [1577.4059322994603, 2117.3274674191302, 2113.379525350715, 2217.492470091315]
params = {
"font.size": 12, # 全局字号
'font.family':'STIXGeneral', # 全局字体
"figure.subplot.wspace":0.2, # 图-子图-宽度百分比
"figure.subplot.hspace":0.4, # 图-子图-高度百分比
"axes.spines.right":False, # 坐标系-右侧线
"axes.spines.top":False, # 坐标系-上侧线
"axes.titlesize":12, # 坐标系-标题-字号
"axes.labelsize": 12, # 坐标系-标签-字号
"legend.fontsize": 12, # 图例-字号
"xtick.labelsize": 10, # 刻度-标签-字号
"ytick.labelsize": 10, # 刻度-标签-字号
"xtick.direction":'in', # 刻度-方向
"ytick.direction":'in' # 刻度-方向
}
#画四条线的预定义
style_dict = {
'y1':dict(linestyle=':', marker='o',markersize=6,color='#fdae61'),
'y2':dict(linestyle='-',marker='*',markersize=6,color='#d7191c'),
'y3':dict(linestyle='--',marker='s',markersize=6,color='#abdda4'),
'y4':dict(linestyle='-.',marker='v',markersize=6,color='#2b83ba')
}
ax.plot(x, y1, **style_dict['y1'])
ax.plot(x, y2, **style_dict['y2'])
ax.plot(x, y3, **style_dict['y3'])
ax.plot(x, y4, **style_dict['y4'])
props = {'xlabel': 'xlabel', # 坐标轴-标签
'ylabel':'ylabel'} # 坐标轴-标签
ax.set(**props)
# 优雅地局部美化格式
fig.legend(('Y1','Y2','Y3','Y4'),frameon=False, loc='upper center',ncol=4,handlelength=4) # 图例
#ax.fill_between(x, MAX, MIN, alpha=0.15, linewidth=0, color='#fdae61') # 阴影
ax.grid(linestyle="--", alpha=0.2) # 网格线
普通矩形图
import matplotlib.pyplot as plt
import numpy as np
# 优雅地创建Figure和Axes
fig, ax = plt.subplots()
# 优雅地添加基础类对象
x = np.arange(4)
MAX = 500; MIN = 0#数据的最大最小值
y1 = [3639.3999062781245, 3411.820969547731, 3134.381409499655, 3108.8418180761682]
y2 = [1554.4144202106154, 2163.045623161998, 2158.4135591973645, 2177.875018596146]
y3 = [2393.778532894126, 2642.3848040954695, 2774.447707450162, 2836.635174277972]
y4 = [1577.4059322994603, 2117.3274674191302, 2113.379525350715, 2217.492470091315]
tick_label = ["10", "20", "30", "40"]
plt.ylabel("Total budget of agents")
bar_width = 0.2
plt.bar(x+3*bar_width, y1, bar_width, color="darkgrey", align="center", label=r'$Y_1$')
plt.bar(x+2*bar_width,y3 , bar_width, align="center", color="red", label=r'$Y_2$')
plt.bar(x+bar_width, y2, bar_width, color="black", align="center", label=r'$Y_3$')
plt.bar(x, y4, bar_width, color="slateblue", align="center", label=r'$Y_4$')
plt.xlabel("The value of M")
#plt.ylim(0,1300)
plt.xticks(x+1*bar_width, tick_label)
plt.legend()
plt.legend()
plt.tight_layout()
plt.show()
plt.close()
图形+注释
import matplotlib.pyplot as plt
import numpy as np
# 优雅地创建Figure和Axes
fig, ax = plt.subplots()
#B1, C1 = truthful_lt(1, 20)
B1 = np.linspace(0, 20, 20)
C1 = [0,0,0,0,0,0,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5]
#B2, C2 = truthful_lt(39, 20)
B2 = np.linspace(0, 20, 20)
C2 = [0,0,0,0,0,0,0,0,0,0,0,0,-2.49,-2.49,-2.49,-2.49,-2.49,-2.49,-2.49,-2.49]
plt.plot(B1, C1, 'red', marker = '8')
plt.title(r'${t}_1^2$')
plt.ylabel("Utility")
plt.xlabel("x")
plt.annotate("y", (7.95944,2.5), xycoords='data',
xytext=(12.5, 1),
arrowprops=dict(arrowstyle='->'))
plt.show()
plt.close()