import sys import matplotlib.pyplot as plt import matplotlib.font_manager as fm font_path = "C:\\Windows\\Fonts\\msyh.ttc" # 这里是微软雅黑的路径,根据需要修改 prop = fm.FontProperties(fname=font_path) plt.rcParams['font.family'] = prop.get_name() def main(): # 第一个参数是脚本路径,忽略它 script_path = sys.argv[0] # 获取传递的参数 filePath = sys.argv[1] title = sys.argv[2] labale = sys.argv[3].split(",") # 接收三个数组参数 values=[int(x) for x in sys.argv[4].split(",")] bars = plt.bar(labale, values) for bar in bars: yval = bar.get_height() plt.text(bar.get_x() + bar.get_width()/2.5, yval, round(yval, 1), va='bottom') # va:vertical alignment plt.title(title) plt.savefig(filePath) if __name__ == "__main__": main()