python利用Matplotlib.pyplot库绘制不同的图形,但是在显示中文时存在部分问题,一般在导入库后,添加如下代码:

  1. # 设置中文正常显示
  2. plt.rcParams['font.sans-serif'] = ['SimHei']
  3. # 设置负号正常显示
  4. plt.rcParams['axes.unicode_minus'] = False

1.折线图

一般折线图

输入:

  1. # 画出折线图
  2.  
  3. import pandas as pd
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6.  
  7. # 设置中文正常显示
  8. plt.rcParams['font.sans-serif'] = ['SimHei']
  9. # 设置负号正常显示
  10. plt.rcParams['axes.unicode_minus'] = False
  11.  
  12. # 读取数据
  13. unrate = pd.read_csv(r'D:\codes_jupyter\数据分析_learning\课件\03_matplotlib\UNRATE.csv', engine='python')
  14.  
  15. # 结合数据形式,将数据的日期格式进行转化
  16. unrate['DATE'] = pd.to_datetime(unrate['DATE'])
  17. print(unrate.head())
  18.  
  19. # 画图
  20. First_twelve = unrate[0:12] # 拿12个月份的数据进行画图
  21.  
  22. # plot()画折线图。函数传入两个值,左边的值作为x轴,右边的值作为y轴
  23. plt.plot(First_twelve['DATE'], First_twelve['VALUE'])
  24. # show()函数显示图片
  25. plt.show()

输出:

折线图设置

对折线图操作,添加标签、标题,并对坐标刻度进行设置

输入:

  1. # 对折线图操作,添加标签、标题,并对坐标刻度进行设置
  2.  
  3. unrate['DATE'] = pd.to_datetime(unrate['DATE'])
  4. First_12 = unrate[0:12]
  5. plt.plot(First_12['DATE'], First_12['VALUE'])
  6.  
  7. # 对横坐标进行一定的变换
  8. # rotation=45 表示转动45°
  9. plt.xticks(rotation=90)
  10.  
  11. # 添加标签
  12. plt.xlabel('月份')
  13. plt.ylabel('失业率')
  14.  
  15. # 添加标题
  16. plt.title('1948年失业率走势')
  17.  
  18. plt.show()

输出:

2.子图

子图概念

fig.add_subplot(4,1,x)函数画子图
 参数表示画4行1列,共4个子图,垂直排列,每行一个图,x表示第x个子图
 参数:(2,2,x)表示两行两列,4个图,每行2个图,x表示第x个子图
 参数:(2,3,x)表示2行3列,每行3个子图,x表示第x个子图

绘制子图

使用add_subplot()绘制子图,并通过figsize()制定画板大小

输入:

  1. # add_subplot()添加子图,figsize()指定画板大小
  2.  
  3. import matplotlib.pyplot as plt
  4.  
  5. # figsize=(x, y)指定画板, 不填写参数表示默认值
  6. # fig = plt.figure()
  7. fig = plt.figure(figsize=(10, 6)) # 通过figsize=(x, y)指定画板大小
  8.  
  9. # 对第一个子图进行操作
  10. ax1 = fig.add_subplot(2, 2, 1)
  11. ax1.plot(np.random.randint(1, 5, 5), np.arange(5)) # 生成随机整数
  12.  
  13. # 对第二个子图进行操作
  14. ax2 = fig.add_subplot(2, 2, 2)
  15. ax2.plot(np.random.randint(1, 5, 5), np.arange(5))
  16.  
  17. # 对第四个子图进行操作
  18. ax4 = fig.add_subplot(2, 2, 4)
  19. ax4.plot(np.random.randint(1, 5, 5), np.arange(5))
  20.  
  21. plt.show()

输出:

绘制多条折线

在一张图上画出多条折线

输入:

  1. # 一张图上画出多条曲线
  2.  
  3. # 拿到日期的月份。
  4. # dt.month获取datetime类型值的月份
  5. unrate['MONTH'] = unrate['DATE'].dt.month
  6.  
  7. # 指定画板大小
  8. fig = plt.figure(figsize=(6, 3))
  9.  
  10. # 画图 通过c='red'指定线条颜色
  11. plt.plot(unrate[:12]['MONTH'], unrate[:12]['VALUE'], c='red')
  12. plt.plot(unrate[12:24]['MONTH'], unrate[12:24]['VALUE'], c='blue')
  13.  
  14. plt.show()

输出:

添加图例1

使用for循环绘制多条折线,并添加对应的图例说明

输入:

  1. # for循环画出多条折线,并添加图例说明
  2.  
  3. fig = plt.figure(figsize=(10, 6))
  4. color = ['r', 'b', 'orange', 'black', 'green']
  5.  
  6. for i in range(5):
  7. start_index = i * 12
  8. end_index = (i+1) * 12
  9.  
  10. # 取范围
  11. subset = unrate[start_index: end_index]
  12.  
  13. # 给每条线添加标签
  14. label = str(1948 + i)
  15. plt.plot(subset['MONTH'], subset['VALUE'], c=color[i], label=label)
  16.  
  17. # 将图例说明自动放置合适位置
  18. plt.legend(loc='best', fontsize=10, ncol=2)
  19. plt.show()
  20.  
  21. # plt.legend()函数显示图例
  22. # loc参数设置位置
  23. # fontsize设置图例字体大小
  24. # ncols 设置用多少列显示图例
  25. # loc='best':将图例说自动添加到合适位置
  26. # loc='center':将图例放置在中心
  27. # 通过print(help(plt.legend))查看其它参数

输出:

设置线条宽度

输入:

  1. # 设置线宽度
  2.  
  3. fig = plt.figure(figsize=(10, 6))
  4. color = ['r', 'b', 'orange', 'black', 'green']
  5. for i in range(5):
  6. start_index = i * 12
  7. end_index = (i+1) * 12
  8. subset = unrate[start_index: end_index]
  9. label = str(1948 + i)
  10.  
  11. # linewidth=10设置线宽度
  12. plt.plot(subset['MONTH'], subset['VALUE'], c=color[i], label=label, linewidth=8)
  13. plt.legend(loc='best', fontsize=10, ncol=2)
  14.  
  15. # xticks的size设置坐标刻度字体的大小,yticks同理设置
  16. plt.xticks(size=30)
  17. plt.yticks(size=15)
  18.  
  19. # 添加标签和标题
  20. plt.xlabel('月份')
  21. plt.ylabel('失业率')
  22. plt.title('1948-1953年失业率走势图')
  23.  
  24. plt.show()

输出:

添加图例2

输入:

  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. women_degree = pd.read_csv(r'D:\codes_jupyter\数据分析_learning\课件\03_matplotlib\percent-bachelors-degrees-women-usa.csv', engine='python')
  5.  
  6. # 设置颜色,label两侧的内容,图例,线宽
  7. plt.plot(women_degree['Year'], women_degree['Biology'], color='blue', label='Women', linewidth=10)
  8. plt.plot(women_degree['Year'], 100-women_degree['Biology'], c='green', label='Men', linewidth=10)
  9.  
  10. # 在图中添加文本信息
  11. plt.text(2005, 35, 'Men', size=25) # 在(2005,35)这个点添加信息,信息内容为后面的字符串,size为字体大小
  12. plt.text(2005, 55, 'Women')
  13.  
  14. # 设置图例
  15. plt.legend(loc='upper right')
  16.  
  17. # 设置title
  18. plt.title('Precentage of Biology Awarded By Gender')
  19.  
  20. # 设置是否显示网格
  21. plt.grid(True)
  22.  
  23. plt.show()

输出:

设置线型、点型及坐标轴

输入:

  1. # 设置线型、点型、坐标轴
  2.  
  3. plt.figure(figsize=(10, 6))
  4. x1 = np.arange(-2*np.pi, 2*np.pi, 0.01)
  5. x2 = np.arange(-2*np.pi, 2*np.pi, 0.2)
  6.  
  7. y1 = np.sin(3*x2)/x2
  8. y2 = np.sin(2*x1)/x1
  9. y3 = np.sin(x1)/x1
  10.  
  11. # linestyle设置线条类型;marker设置线条上点的风格
  12. plt.plot(x2, y1, c='b', linestyle='--', marker='^')
  13. plt.plot(x1, y2, c='r', linestyle='-')
  14. plt.plot(x1, y3, c='g')
  15.  
  16. # 获取Axes对象
  17. ax = plt.gca()
  18. # spines['right']获取有边框
  19. ax.spines['right'].set_color('none') # set_color设置颜色为none
  20. # spines['top']获取上边框
  21. ax.spines['top'].set_color('none') # set_color设置颜色为none
  22.  
  23. # 设置坐标轴
  24. ax.xaxis.set_ticks_position('bottom') # 设置下边框为x轴
  25. ax.spines['bottom'].set_position(('data', 0)) # 获取下边框,set_position设置坐标轴位置
  26.  
  27. ax.yaxis.set_ticks_position('left') # 设置左边框为y轴
  28. ax.spines['left'].set_position(('data', 0)) # 设置y轴显示在刻度范围内,0的地方
  29.  
  30. plt.show()
  31.  
  32. # set_position()传入元组
  33. # ('data', 0) 表示将x轴放到数字0的位置
  34. # 下面的一个表示将y轴放到数字0的位置
  35. # 使用print(help(ax.spine['left'].set_position))查看帮助文档
  36. # data 表示将坐标轴设置在刻度范围内部
  37. # outwards 表示将坐标轴设置在整体刻度范围的最外面
  38. # 第一个0 表示x轴在y轴的刻度0的地方,第二个0同理

输出:

设置刻度及坐标轴显示

输入:

  1. # 设置刻度的显示、显示图的一部分
  2.  
  3. plt.figure(figsize=(10, 6))
  4. x1 = np.arange(-2*np.pi, 2*np.pi, 0.01)
  5. x2 = np.arange(-2*np.pi, 2*np.pi, 0.2)
  6.  
  7. y1 = np.sin(3*x2)/x2
  8. y2 = np.sin(2*x1)/x1
  9. y3 = np.sin(x1)/x1
  10.  
  11. # linestyle设置线条类型;marker设置线条上点的风格
  12. plt.plot(x2, y1, c='b', linestyle='--', marker='^')
  13. plt.plot(x1, y2, c='r', linestyle='-')
  14. plt.plot(x1, y3, c='g')
  15.  
  16. # 设置要显示刻度的刻度值
  17. # plt.xticks([-2*np.pi, -np.pi, 0, np.pi, 2*np.pi])
  18.  
  19. # 用后面的刻度,替换前面的刻度值
  20. plt.xticks([-2*np.pi, -np.pi, 0, np.pi, 2*np.pi], ['-2π', '-π', '', 'π', '2π'], size=15)
  21.  
  22. # 设置只显示刻度范围内的值
  23. # plt.xlim((-1 * np.pi, np.pi))
  24. # plt.ylim((0, 3))
  25.  
  26. plt.show()

输出:

3.柱形图

  1. # 读取数据
  2. import pandas as pd
  3.  
  4. review = pd.read_csv(r'D:\codes_jupyter\数据分析_learning\课件\03_matplotlib\fandango_scores.csv', engine='python')
  5. cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'RT_norm', 'Fandango_Stars']
  6.  
  7. # 取出对应列
  8. norm_review = review[cols]
  9. norm_review.head()
  1. FILM RT_user_norm Metacritic_user_nom IMDB_norm RT_norm Fandango_Stars
  2. 0 Avengers: Age of Ultron (2015) 4.3 3.55 3.90 3.70 5.0
  3. 1 Cinderella (2015) 4.0 3.75 3.55 4.25 5.0
  4. 2 Ant-Man (2015) 4.5 4.05 3.90 4.00 5.0
  5. 3 Do You Believe? (2015) 4.2 2.35 2.70 0.90 5.0
  6. 4 Hot Tub Time Machine 2 (2015) 1.4 1.70 2.55 0.70 3.5

一般柱形图

输入:

  1. # plt.bar函数,画柱形图
  2.  
  3. # 首先,指定柱的高度
  4. bar_height = norm_review.loc[0, cols[1:]].values # 这里就取5家媒体对0号电影的评分值
  5.  
  6. # 其次,指定柱的位置
  7. bar_position = np.arange(5) + 1
  8. # print(bar_position)
  9.  
  10. plt.figure(figsize=(10, 6))
  11.  
  12. # 使用plt.bar函数画柱状图
  13. plt.bar(bar_position, bar_height, 0.5) # 0.5是设置柱的宽度
  14. plt.show()

输出:

设置柱状图的颜色、文本注释、坐标轴格式、标题和标签

输入:

  1. # 设置柱状图的颜色、文本注释、坐标轴格式、标题和标签
  2.  
  3. bar_height = norm_review.loc[0, cols[1:]].values
  4. bar_position = np.arange(5) + 1
  5. plt.figure(figsize=(10, 6))
  6.  
  7. # color属性,设置颜色
  8. plt.bar(bar_position, bar_height, 0.5, color=['r', 'g', 'b']) # 设置一种颜色直接color=‘r’
  9.  
  10. # xticks替换坐标, 利用电影名替换1,2,3,。。。
  11. plt.xticks(bar_position, cols[1:])
  12.  
  13. #设置标签和标题
  14. plt.xlabel("评分公司")
  15. plt.ylabel("评分")
  16. plt.title("5家公司对电影0的评分情况")
  17.  
  18. # 利用plt.text方法,设置具体数值
  19. for x, y in zip(bar_position, bar_height):
  20. plt.text(x, y, '%.2f'% y, ha='center', va='bottom', size=14)
  21.  
  22. # 说明:
  23. # plt.text()依次传入坐标和字符串内容
  24. # x,y 代表传入柱的位置和高度
  25. # '%.2f' 代表传入字符串的内容
  26. # ha='center' 设置文字水平对齐方式,其他参数查看帮助文档
  27. # va='bottom' 设置文字垂直对齐方式,其他参数查看帮助文档
  28. # size 设置字体大小
  29.  
  30. plt.show()

输出:

横向柱形图

输入:

  1. # plt.barh画横向柱状图
  2.  
  3. # 设置柱的高度
  4. bar_width = norm_review.loc[0, cols[1:]].values
  5. # 设置柱的位置
  6. bar_position = np.arange(5) + 1
  7.  
  8. # 设置画板大小
  9. plt.figure(figsize=(10, 6))
  10.  
  11. # 设置标签和标题
  12. plt.xlabel('评分公司')
  13. plt.ylabel('分数')
  14. plt.title('公司评分分布图')
  15.  
  16. # 设置坐标轴
  17. plt.yticks(bar_position, cols[1:])
  18.  
  19. # 添加文本注释
  20. for x,y in zip(bar_width, bar_position):
  21. plt.text(x,y, '%.2f'%x, ha='left', va='center', size=14)
  22.  
  23. # 画出柱状图
  24. plt.barh(bar_position, bar_width, 0.5, color=['r', 'g', 'b'])
  25. plt.show()

输出:

4.散点图

一般散点图

输入:

  1. # plt.scatter()画出散点图
  2.  
  3. # 设置画板大小
  4. plt.figure(figsize=(10, 6))
  5.  
  6. # 传入每个点的x,y坐标
  7. plt.scatter(norm_review['RT_user_norm'], norm_review['Metacritic_user_nom'])
  8.  
  9. # 设置标签
  10. plt.xlabel('RT_user_norm')
  11. plt.ylabel('Metacritic_user_nom')
  12. plt.title('两家媒体对同一电影的评分')
  13.  
  14. plt.show()

输出:

散点图加子图

输入:

  1. # 散点图加子图
  2.  
  3. # 新建画板
  4. fig = plt.figure(figsize=(10, 6))
  5.  
  6. # 添加子图
  7. ax1 = fig.add_subplot(2, 1, 1)
  8. ax2 = fig.add_subplot(2, 1, 2)
  9.  
  10. # 画出子图,并进行设置
  11. ax1.scatter(norm_review['RT_user_norm'], norm_review['Metacritic_user_nom'])
  12. ax1.set_xlabel('RT_user_norm') # 添加标签
  13. ax1.set_ylabel('Metacritic_user_nom')
  14.  
  15. ax2.scatter(norm_review['RT_user_norm'], norm_review['Metacritic_user_nom'],s=10, c='r', marker='^' )
  16. # s=10 设置点的大小
  17. # c='r' 设置颜色
  18. # marker='^' 设置点的类型
  19. ax2.set_xlabel('RT_user_norm') # 添加标签
  20. ax2.set_ylabel('Metacritic_user_nom')
  21.  
  22. plt.show()

输出:

输入:

  1. """
  2. 需求说明:
  3. 读取pandas_practice数据
  4. 一共两个科目的分数,
  5. 通过的用红色 x 表示
  6. 淘汰的用蓝色 . 表示
  7. 添加图例等相关信息
  8. """
  9. import numpy as np
  10. import pandas as pd
  11. import matplotlib.pyplot as plt
  12.  
  13. # 数据读取
  14. datas = pd.read_csv(r'D:\codes_jupyter\数据分析_learning\课件\03_matplotlib\pandas_practice.csv', engine='python')
  15.  
  16. # 指定画板大小
  17. fig = plt.figure(figsize=(10,4))
  18.  
  19. # 取出所有通过的人Exam1分数和Exam2分数,添加标签,指定颜色和点型
  20. plt.scatter(datas['Exam1'][(datas['Admitted'] == 1)], datas['Exam2'][(datas['Admitted'] == 1)], label="通过", s=14, c='r', marker='x')
  21. # 取出所有淘汰的人的分数,添加相关内容
  22. plt.scatter(datas['Exam1'][(datas['Admitted'] == 0)], datas['Exam2'][(datas['Admitted'] == 0)], label="淘汰", s=14, c='b')
  23.  
  24. # 添加标签
  25. plt.xlabel('科目1分数')
  26. plt.ylabel('科目2分数')
  27.  
  28. # 添加图例
  29. plt.legend(loc='best')
  30.  
  31. plt.show()

输出:

5.条形图

数据展示:

  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. reviews = pd.read_csv(r'D:\codes_jupyter\数据分析_learning\课件\03_matplotlib\fandango_scores.csv', engine='python')
  6. cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'RT_norm', 'Fandango_Stars']
  7.  
  8. norm_reviews = reviews[cols]
  9. norm_reviews.head()
  1. FILM RT_user_norm Metacritic_user_nom IMDB_norm RT_norm Fandango_Stars
  2. 0 Avengers: Age of Ultron (2015) 4.3 3.55 3.90 3.70 5.0
  3. 1 Cinderella (2015) 4.0 3.75 3.55 4.25 5.0
  4. 2 Ant-Man (2015) 4.5 4.05 3.90 4.00 5.0
  5. 3 Do You Believe? (2015) 4.2 2.35 2.70 0.90 5.0
  6. 4 Hot Tub Time Machine 2 (2015) 1.4 1.70 2.55 0.70 3.5

频数分布图

输入:

  1. # 对某家媒体的评分进行统计,拿到评分的频数分布,并画出频数分布图
  2.  
  3. # 利用value_counts()函数,对不同评分进行统计,得到频数
  4. # fandango_distribute = norm_reviews['RT_user_norm'].value_counts()
  5. # print(fandango_distribute)
  6.  
  7. # 利用sort_index()函数,按照索引排序
  8. # fandango_sort = fandango_distribute.sort_index()
  9. # print(fandango_sort)
  10.  
  11. # plt.hist()函数画出频数分布图
  12. plt.hist(norm_reviews['RT_user_norm'], bins=20, range=(4, 5), edgecolor='black', rwidth=0.8)
  13. # bins=20 将原来数据的范围分为20份
  14. # edgecolot 设置边框的颜色
  15. # rwidth 设置条形的宽度
  16. # range=(4, 5) 可选参数 设置只显示4到5之间的频数分布
  17.  
  18. plt.show()

输出:

6.三维图

三维线图

输入:

  1. from mpl_toolkits.mplot3d import Axes3D
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. # 构造一个3D画板
  6. fig = plt.figure()
  7. ax = Axes3D(fig)
  8.  
  9. x = np.arange(-2, 2, 0.1)
  10. y = np.arange(-2, 2, 0.1)
  11. def f(x, y):
  12. return (x**2 + y**2)
  13.  
  14. # 传入(x,y,z)坐标
  15. ax.plot(x, y, f(x, y), color='r') # 画图
  16.  
  17. # 设置标签
  18. ax.set_xlabel('x label')
  19. ax.set_ylabel('y label')
  20. ax.set_zlabel('z label')
  21.  
  22. plt.show()

输出:

三维平面图

输入:

  1. # 构造空间图
  2.  
  3. # 构造一个3D画板
  4. fig = plt.figure()
  5. ax = Axes3D(fig)
  6.  
  7. x = np.arange(-2, 2, 0.1)
  8. y = np.arange(-2, 2, 0.1)
  9. # 将x,y构成点矩阵
  10. x, y = np.meshgrid(x, y)
  11.  
  12. def f(x, y):
  13. return (x**2 + y**2)
  14.  
  15. # 传入(x,y,z)坐标
  16. ax.plot_surface(x, y, f(x, y), color='r') # 画图
  17.  
  18. # 设置标签
  19. ax.set_xlabel('x label')
  20. ax.set_ylabel('y label')
  21. ax.set_zlabel('z label')
  22.  
  23. plt.show()

输出:

三维散点图

输入:

  1. # 构造一个空间散点图
  2.  
  3. # 构造一个3D画板
  4. fig = plt.figure()
  5. ax = Axes3D(fig)
  6.  
  7. x = np.arange(-2, 2, 0.1)
  8. y = np.arange(-2, 2, 0.1)
  9. # 将x,y构成点矩阵
  10. x, y = np.meshgrid(x, y)
  11.  
  12. def f(x, y):
  13. return (x**2 + y**2)
  14.  
  15. # 传入(x,y,z)坐标
  16. ax.scatter3D(x, y, f(x, y), color='g', marker='*', s=10) # 画图
  17.  
  18. # 设置标签
  19. ax.set_xlabel('x label')
  20. ax.set_ylabel('y label')
  21. ax.set_zlabel('z label')
  22.  
  23. plt.show()

输出:

03_Matplotlib的基本使用的更多相关文章

随机推荐

  1. 在SpringBoot中使用flyway进行数据库版本管理

    本文大纲 flyway是什么 能帮助我们解决什么问题 springboot环境下使用flyway flyway的工作原理 一.flyway是什么 Flyway是一个开源的数据库版本管理工具,并且极力主 ...

  2. token和session

    什么是token? token是服务端生成的一串字符串,目的是作为客户端进行请求的一个令牌.当第一次登录后,服务器生成一个token(一串字符串),并将此token返回给客户端,此后页面接收到请求后, ...

  3. VB.NET 与 SAP RFC连接问题点

    与SAP RFC连接,电脑上必须要安装SAP软件,否则会报错ActiveX 输入工单号,无法带出SAP内接口RFC信息. 确认原因为:RFC接口需求的工单参数需要在前面加两位00,例如:1000541 ...

  4. Django学习day2——Django安装与环境配置

    安装 Django 文章中python版本为3.65 这里以windows7为例,在pip目录下运行pip install Django就能安装django最新版本(本文为django2.2版本) 也 ...

  5. FastJson稍微使用不当就会导致StackOverflow

    GitHub 9.4k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 9.4k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 9.4k Star 的 ...

  6. 查看redis占用内存大小的方法

    查看redis占用内存大小的方法 <pre>redis-cli auth 密码info</pre><pre># Memory used_memory:1349009 ...

  7. 【Go 入门学习】第一篇关于 Go 的博客--Go 爬虫初体验

    一.写在前面 其实早就该写这一篇博客了,为什么一直没有写呢?还不是因为忙不过来(实际上只是因为太懒了).不过好了,现在终于要开始写这一篇博客了.在看这篇博客之前,可能需要你对 Go 这门语言有些基本的 ...

  8. hash值生成表后缀(分表方案)

    //businessId分表目标值,tableSize:表数量,tableSuffix:表后缀 public static String getTableSuffix(String businessI ...

  9. 监听器以及在监听类里面获得bean的方法

    1实现HttpSessionListener和ServletContextListener,2个接口 2然后在contextInitialized初始化方法里面: ServletContext app ...

  10. PHP Swoole长连接常见问题

    连接失效问题例子其中,Redis常见的报错就是: 配置项:timeout报错信息:Error while reading line from the serverRedis可以配置如果客户端经过多少秒 ...