scipy 光滑散点图
from scipy.interpolate import make_interp_spline
import matplotlib.pyplot as plt
import numpy as np
def SmoothData(x, y):
x_smooth = np.linspace(x.min(), x.max(), 3000)
y_smooth = make_interp_spline(x, y)(x_smooth)
return x_smooth, y_smooth
fig = plt.figure(figsize=(12, 5))
ax1, ax2 = fig.subplots(2, 1)
x = np.arange(1, 101, 20)
y = x ** 3
x_smooth, y_smooth = SmoothData(x, y)
ax2.plot(x_smooth, y_smooth)
ax2.scatter(x, y, s=12)
ax1.plot(x, y, '-o', lw=2)
ax1.grid(alpha=0.3)
ax2.grid(alpha=0.3)
plt.show()