# Python绘制二维曲线的日常应用详解

```#!/usr/bin/python

import numpy as np

import matplotlib.pyplot as plt

from xlrd import open_workbook

def SportLine(excel_file):

days_year  = []

target_km  = []

records   = []

sum_records = []

pct_records = []

target_pct  = []

fig,axs = plt.subplots(3)

for i in range(365):

days_year.append(i)

for day in days_year:

target_km.append(float(day)/365.0 * 1000.0)

book = open_workbook(excel_file)

sheet = book.sheet_by_name("record")

rows_num = sheet.nrows

cols_num = sheet.ncols

for row_num in range(3,368):

try:

records.append(float(sheet.cell(row_num,1).value))

except:

records.append(0.0)

# calculate sum of records

sum_record = 0.0

for each_record in records:

sum_record += each_record

sum_records.append(sum_record)

# calculate pct of all

for each_sum in sum_records:

pct_records.append(each_sum / 1000.0)

# calculate target pct

for day in range(1,366):

target_pct.append(float(day)/365.0)

# plot target and sum trend

ax = axs[0]

ax.plot(days_year,sum_records)

ax.plot(days_year,target_km)

ax.set_title("distance-year-km")

ax.grid(True)

# plot record

ax = axs[1]

ax.plot(days_year,records)

ax.set_title("distance-day-km")

ax.grid(True)

# plot percentage

ax = axs[2]

ax.plot(days_year,pct_records)

ax.plot(days_year,target_pct)

ax.set_title("pct-100%")

ax.grid(True)

plt.show()

SportLine("records.xlsx")
```