第1关:画图接口

1
2
3
4
5
6
7
8
9
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def student(x,y):
# ********** Begin *********#
fig = plt.figure(figsize=(10,10))
plt.savefig("Task1/image1/T2.png")
plt.show()
# ********** End *********#

第2关:线形图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt


def student(input_data,input_data1):

# ********* Begin *********#
fig = plt.figure(figsize=(10,10))
plt.plot(input_data,'--g')
plt.plot(input_data1,':r')
plt.legend(['L1','L2'])
plt.savefig("Task2/img/T1.png")
plt.show()
# ********* End *********#

第3关:散点图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np

def student(x,y,x2,y2,x3,y3,area):
'''
根据输入的三组数据绘制三组不同参数的散点图
:param x,y: 第一组数据,类型为array
:param x2,y2: 第二组数据,类型为array
:param x3,y3: 第三组数据,类型为array
:param area: 标记大小参数的值,类型为array
:return: None
'''
# ********* Begin *********#
fig = plt.figure(figsize=(10,10))
plt.scatter(x,y,s = area, alpha = 0.5)
plt.scatter(x2,y2,s = area, c = 'g', alpha = 0.6)
plt.scatter(x3,y3,s = area, marker = 'v', alpha = 0.7)
plt.savefig("Task3/img/T1.png")
plt.show()
# ********* End *********#

第4关:直方图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import matplotlib
matplotlib.use("Agg")
import numpy as np
import matplotlib.pyplot as plt



def student(data,x,y):
'''
根据输入数据将直方图与线形图绘制在同一面板中,并设置直方图为红色,线形图为蓝色
:param data: 绘制直方图数据,类型为list
:param x,y: 绘制线形图数据,类型为list

:return: None
'''
# ********* Begin *********#
fig = plt.figure(figsize=(10,10))
plt.hist(data,facecolor="red")
plt.plot(x,y,color="blue")
plt.savefig("Task4/img/T1.png")
plt.show()
# ********* End *********#

第5关:饼图

1
2
3
4
5
6
7
8
9
10
11
12
13
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np

def student(labels,quants):
# ********* Begin *********#
fig=plt.figure(figsize=(6,6))
sizes = quants
plt.pie(sizes,labels=labels,explode=(0,0.1,0,0,0,0,0,0,0,0),autopct='%1.1f%%')
plt.savefig("Task5/img/T1.png")
plt.show()
# ********* End *********#