|
- 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(",")]
- # 打印参数
- plt.pie( values, labels=labale, colors=['gold', 'yellowgreen', 'lightcoral', 'lightskyblue'],autopct='%1.1f%%')
- # 确保饼图是圆形的
- plt.axis('equal')
- # 添加标题
- # 显示图表
- plt.title(title)
- # plt.show()
- plt.savefig(filePath)
-
- if __name__ == "__main__":
- main()
|