如何使用python创建一个简单的饼图

 一个具有骨感的女人0 发布于 2023-02-08 18:37

我一直试图使用python生成一个简单的饼图,只使用两个变量.代表百分比.我总是"vcvarsall.bat" not found在安装matplotlib包时遇到错误.是不是已经不可避免地要安装Visual Studio了?

1 个回答
  • Visual Studio不需要安装matplotlib.为了获得最佳结果,首先从python.org安装Python,32位或64位,具体取决于您的计算机的体系结构和您运行的Windows版本(例如,即使您有64位处理器,如果您'重新运行32位Windows,下载32位Python).版本并不特别重要,我更喜欢3.3.3,但更多的软件包与2.7.6兼容,所以请选择.Matplotlib及其依赖项都可用于任一版本.

    接下来,转到Christoph Gohlke的Windows Python扩展包,并为您的Python版本下载以下包:

    matplotlib

    numpy

    python-dateutil

    pytz

    pyparsing

    six

    Pillow

    tornado

    pyside

    pyqt

    这些包都是自解压安装程序.以任何顺序运行它们,当你完成后,你应该能够导入并使用matplotlib就好了.

    一个示例饼图程序,从这里:

    from pylab import *
    
    # make a square figure and axes
    figure(1, figsize=(6,6))
    ax = axes([0.1, 0.1, 0.8, 0.8])
    
    # The slices will be ordered and plotted counter-clockwise.
    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
    fracs = [15, 30, 45, 10]
    explode=(0, 0.05, 0, 0)
    
    pie(fracs, explode=explode, labels=labels,
                    autopct='%1.1f%%', shadow=True, startangle=90)
                    # The default startangle is 0, which would start
                    # the Frogs slice on the x-axis.  With startangle=90,
                    # everything is rotated counter-clockwise by 90 degrees,
                    # so the plotting starts on the positive y-axis.
    
    title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
    
    show()
    

    2023-02-08 18:38 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有