Matplotlib _ 05 细节设置

走远了吗. 提交于 2020-01-31 04:39:36
import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")
plt.plot(women_degrees['Year'],women_degrees['Biology']) 

plt.show()

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")
plt.plot(women_degrees['Year'],women_degrees['Biology'],c='blue',label='Women') 
plt.plot(women_degrees['Year'], 100-women_degrees['Biology'], label='Men')

plt.tick_params(bottom="off", top="off", left="off", right="off")
plt.set_title('Percentage of Biology Degrees Awarded By Gender')
plt.legend(loc="upper right")

plt.show()

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")

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)
# End solution code.
ax.legend(loc='upper right')
plt.show()

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")

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')
    # Add your code here.

# 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()

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")

#Setting Line Width
cb_dark_blue = (0/255, 107/255, 164/255)
cb_orange = (255/255, 128/255, 14/255)

fig = plt.figure(figsize=(12, 12))

for sp in range(0,4):
    ax = fig.add_subplot(2,2,sp+1)
    # Set the line width when specifying how each line should look.
    ax.plot(women_degrees['Year'], women_degrees[major_cats[sp]], c=cb_dark_blue, label='Women', linewidth=10)
    ax.plot(women_degrees['Year'], 100-women_degrees[major_cats[sp]], c=cb_orange, label='Men', linewidth=10)
    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")

plt.legend(loc='upper right')
plt.show()

 

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")

stem_cats = ['Engineering', 'Computer Science', 'Psychology', 'Biology', 'Physical Sciences', 'Math and Statistics']
fig = plt.figure(figsize=(18, 3))

for sp in range(0,6):
    ax = fig.add_subplot(1,6,sp+1)
    ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
    ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
    for key,spine in ax.spines.items():
        spine.set_visible(False)
    ax.set_xlim(1968, 2011)
    ax.set_ylim(0,100)
    ax.set_title(stem_cats[sp])
    ax.tick_params(bottom="off", top="off", left="off", right="off")

plt.legend(loc='upper right')
plt.show()

 

 

import pandas as pd
import matplotlib.pyplot as plt

women_degrees = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/percent-bachelors-degrees-women-usa.csv")

fig = plt.figure(figsize=(18, 3))

for sp in range(0,6):
    ax = fig.add_subplot(1,6,sp+1)
    ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
    ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
    for key,spine in ax.spines.items():
        spine.set_visible(False)
    ax.set_xlim(1968, 2011)
    ax.set_ylim(0,100)
    ax.set_title(stem_cats[sp])
    ax.tick_params(bottom="off", top="off", left="off", right="off")
plt.legend(loc='upper right')
plt.show()
fig = plt.figure(figsize=(18, 3))

for sp in range(0,6):
    ax = fig.add_subplot(1,6,sp+1)
    ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
    ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
    for key,spine in ax.spines.items():
        spine.set_visible(False)
    ax.set_xlim(1968, 2011)
    ax.set_ylim(0,100)
    ax.set_title(stem_cats[sp])
    ax.tick_params(bottom="off", top="off", left="off", right="off")
    
    if sp == 0:
        ax.text(2005, 87, 'Men')
        ax.text(2002, 8, 'Women')
    elif sp == 5:
        ax.text(2005, 62, 'Men')
        ax.text(2001, 35, 'Women')
plt.show()

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!