如题, 分享一个在python中画柱状图的原代码, 其效果图如下:
它的特点是:
- 有标签且标签在图片外侧
- 使用了希腊字母
- 在每个柱子上边标明了柱子的高度
原代码如下(建议用python3编译, 因为python2的编译结果会有所不同):
import json
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.patches import Ellipse
import numpy as np
font = {'size':18}
matplotlib.rc('font', **font)
if __name__ == "__main__":
AE1 = [7, 10, 13, 17, 21, 25]
AE2 = [9, 8, 4, 6, 15, 22]
fig = plt.figure(1)
ax = fig.add_axes([0,0,1,1])
ax.set_xlim([0,7])
ax.set_ylim([0,27])
plt.xlabel("N")
plt.ylabel("AE")
plt.xticks(range(1, 7), [r"$\gamma$", r"$\beta$", r"$\lambda$", r"$\tau$", r"$\theta$", r"$\phi$"])
rects = ax.patches
labels1 = [str(item) for