scipy 光滑散点图

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()
1.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容