matplotlib使用记录

  1. 显示中文乱码问题
import matplotlib.pyplot as plt
# mac中
plt.rcParams['font.sans-serif']='Heiti TC'
# windows中
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
# 负号正常显示
plt.rcParams['axes.unicode_minus'] = False  # 负号正常显示
  1. 画折线图
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 2.4, 3, 4, 5.3, 6])
y = np.array([3, 2, 5, 4.2, 4 ,7.2])
plt.plot(x,y)
  1. 画散点图
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 2.4, 3, 4, 5.3, 6])
y = np.array([3, 2, 5, 4.2, 4 ,7.2])
plt.scatter(x,y)
  1. 坐标轴旋转(坐标是日期的时候很有用)
plt.xticks(rotation=60) # 旋转60度
posted @ 2022-10-17 17:16  裏表異体  阅读(19)  评论(0编辑  收藏  举报