• Python数据分析与机器学习-Matplot_5


    import pandas as pd
    import matplotlib.pyplot as plt
    
    women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
    plt.plot(women_degrees['Year'],women_degrees['Biology'])
    plt.show()
    

    #100-women_degrees means men
    plt.plot(women_degrees['Year'], women_degrees['Biology'], c='blue', label='Women')
    plt.plot(women_degrees['Year'], 100-women_degrees['Biology'], c='green', label='Men')
    plt.legend(loc='best')
    plt.title('Percentage of Biology Degrees Awarded By Gender')
    
    Text(0.5, 1.0, 'Percentage of Biology Degrees Awarded By Gender')
    

    # fig, ax = plt.subplots()
    fig, ax = plt.subplots()
    ax.plot(women_degrees['Year'], women_degrees['Biology'], label='Women')
    ax.plot(women_degrees['Year'], 100-women_degrees['Biology'], label='Men')
    
    ax.tick_params(bottom="off",top="off", left="off", right="off")
    ax.set_title('Percentage of Biology Degrees Awarded By Gender')
    ax.legend(loc="upper right")
    plt.show()
    

    fig, ax = plt.subplots()
    ax.plot(women_degrees['Year'], women_degrees['Biology'], c='blue', label='Women')
    ax.plot(women_degrees['Year'], 100-women_degrees['Biology'], c='green', label='Men')
    ax.tick_params(bottom="off",top="off", left="off", right="off")
    
    for key,spine in ax.spines.items():
        spine.set_visible(False)
    ax.legend(loc='upper right')
    plt.show()
    

    major_cats = ['Biology', 'Computer Science', 'Engineering', 'Math and Statistics']
    fig = plt.figure(figsize=(12, 12))
    
    for sp in range(0,4):
        ax = fig.add_subplot(2,2,sp+1)
        ax.plot(women_degrees['Year'], women_degrees[major_cats[sp]], c='blue', label='Women')
        ax.plot(women_degrees['Year'], 100-women_degrees[major_cats[sp]], c='green', label='Men')
    
    # Calling pyplot.legend() here will add the legend to the last subplot that was created.
    plt.legend(loc='upper right')
    plt.show()
    
    major_cats = ['Biology', 'Computer Science', 'Engineering', 'Math and Statistics']
    fig = plt.figure(figsize=(12, 12))
    
    for sp in range(0,4):
        ax = fig.add_subplot(2,2,sp+1)
        ax.plot(women_degrees['Year'], women_degrees[major_cats[sp]], c='blue', label='Women')
        ax.plot(women_degrees['Year'], 100-women_degrees[major_cats[sp]], c='green', label='Men')
        #for key,spine in ax.spines.items():
        #    spine.set_visible(False)
        ax.set_xlim(1968, 2011)
        ax.set_ylim(0,100)
        ax.set_title(major_cats[sp])
        ax.tick_params(bottom="off", top="off", left="off", right="off")
    
    # Calling pyplot.legend() here will add the legend to the last subplot that was created.
    plt.legend(loc='upper right')
    plt.show()
    

  • 相关阅读:
    Redis分布式锁解决抢购问题
    Linux查看进程,端口,服务路径等
    执行jar包,输出信息到文件
    查看linux服务器信息
    IDEA将项目打包为指定class文件的jar
    RSA加密-解密以及解决超长内容加密失败解决
    win10 Snipaste 截图软件
    线程池参数详解
    本地连接Linux工具
    python安装
  • 原文地址:https://www.cnblogs.com/SweetZxl/p/11126908.html
Copyright © 2020-2023  润新知