单个图绘制柱状图
ax1.title.set_text('scores')
ll = [round(i,2) for i in bins] ## list
ax1.set_xticks(ll)
ax1.set_xticklabels(['one','two','three','four','five'],rotation = 30,fontsize = 'small') # 设置刻度标签
ax1.set_xlabel('Score Error')
y方向的label设置类似
plt.suptitle("Compare between {}".format(info))
fig.text(0.08, 0.5, 'Number of Points', va='center', rotation='vertical')
## 两个数字是文字放置的坐标
主图x轴注释的设置
fig.text(0.5, 0, 'xlabel', ha='center')
子图相关设置通过ax实现,主图的相关设置通过fig或者plt实现
fig = plt.figure(figsize=(25, 6), facecolor='gray')
ax1 = fig.add_subplot(1, 3, 1) # 第一行的第一个图
# nums, bins, patches = ax1.hist(score_list_total, alpha=0.5)
nums, bins, patches = ax1.hist(score_list_total,bins=12)
ax1.title.set_text('scores')
# ax1.set_xticklabels("{:.3f}".format(i) for i in bins)
ll = [round(i,2) for i in bins]
ax1.set_xticks(ll)
ax1.set_xlabel('Score Error')
# ax1.set_ylabel('Number of Points')
for num, bin in zip(nums, bins):
# plt.annotate("%.4f" % num, xy=(round(bin,4), int(num)), xytext=(round(bin,4) , int(num)))
plt.annotate(int(num), xy=(round(bin,4), int(num)), xytext=(round(bin,4)+0.008 , int(num)+3))
ax2 = fig.add_subplot(1, 3, 2) # 第一行的第二个图
# nums2, bins2, patches2 = ax2.hist(x_list_total, alpha=0.5)
nums2, bins2, patches2 = ax2.hist(x_list_total,bins=12)
ax2.title.set_text('x')
# ax2.set_xticklabels(round(i, 3) for i in bins2)
ll = [round(i, 3) for i in bins2]
ax2.set_xticks(ll)
ax2.set_xlabel('x Error')
# ax2.set_ylabel('Number of Points')
for num, bin in zip(nums2, bins2):
# plt.annotate("%.4f" % num, xy=(round(bin,4), int(num)), xytext=(round(bin,4) , int(num)))
plt.annotate(int(num), xy=(round(bin, 4), int(num)), xytext=(round(bin, 4) + 0.8, int(num) + 3))
ax3 = fig.add_subplot(1, 3, 3) # 第一行第三个图
nums3, bins3, patches3 = ax3.hist(y_list_total,bins=12)
ax3.title.set_text('y')
# ax3.set_xticklabels(round(i, 3) for i in bins3)
ll = [round(i, 3) for i in bins3]
ax3.set_xticks(ll)
ax3.set_xlabel('y Error')
for num, bin in zip(nums3, bins3):
# plt.annotate("%.4f" % num, xy=(round(bin,4), int(num)), xytext=(round(bin,4) , int(num)))
plt.annotate(int(num), xy=(round(bin, 4), int(num)), xytext=(round(bin, 4) + 0.8, int(num) + 3))
# plt.ylabel('Number of Points')
fig.text(0.08, 0.5, 'Number of Points', va='center', rotation='vertical')
# plt.title("Compare between {}".format(info))
plt.suptitle("Compare between {}".format(info))
plt.savefig(info + '.png')
fig = plt.figure(figsize=(15, 10))
ax1 = fig.add_subplot(2, 2, 1)
ax1.plot(left_ankle_list[10:])
ax1.plot(right_ankle_list[10:])
ax1.legend(['left_ankle','right_ankle']) ## 添加图例。数组里面的第一个图表示画的第一条曲线的图例
ax1.set_title('left and right ankles coordinate for instant')
ax1.get_xaxis().set_visible(False)# 隐藏x坐标轴
ax1.get_yaxis().set_visible(False)# 隐藏y坐标轴
ax2.get_xaxis().set_visible(False)
ax2.get_yaxis().set_visible(False)