折线图-小案例

01-设置全局字体+大小
02-绘制多条直线
03-折线图-蓝色点+红色线+坐标


 

01-设置全局字体+大小

import matplotlib.pyplot as plt
import matplotlib  # 载入matplotlib完整库

matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10

a = range(10)
x = a
y = a
plt.plot(x, y)  # 折线图
plt.grid()  # 设置网格
plt.show()  # 显示图形

  


02-绘制多条直线

import matplotlib.pyplot as plt
import numpy as np
import matplotlib  # 载入matplotlib完整库

matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10

a = np.arange(10)
plt.figure(figsize=(20, 20), dpi=80)
# 方法一:
# plt.plot(a, a, a, a * 1.5, a, a * 3)  # 折线图
# 方法二:
plt.plot(a, a)  # 折线图
plt.plot(a, a * 1.5)  # 折线图
plt.plot(a, a * 3)  # 折线图

plt.grid()  # 设置网格
plt.show()  # 显示图形

  


03-折线图-蓝色点+红色线+坐标

import matplotlib.pyplot as plt
import numpy as np
import matplotlib  # 载入matplotlib完整库

matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
# matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10

a = np.arange(10)
# y = x ** 2
x = a
y = list(map(lambda i: i ** 2, a))

plt.figure(figsize=(20, 20), dpi=80)

plt.plot(x, y, color='r', markerfacecolor='blue', marker='o')
for i, j in zip(x, y):
    plt.text(i + 0.3, j - 6, (i, j), ha='center', va='bottom', fontsize=30)  # 标记文本

plt.legend(apha=0.1)

plt.grid()  # 设置网格
plt.show()  # 显示图形

  

posted @ 2018-11-01 19:08  安迪9468  阅读(512)  评论(0编辑  收藏  举报