[Python] Smooth curve through points with prepar1d

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to get a smooth curve through the data points, but the curve is not smooth and it just connects the scatter points with a straight line or it shows weird bumps in the area between the points, how can I smooth this curve?

    import numpy as np
    import pandas as pd
    from matplotlib import pyplot as plt
    import matplotlib.pyplot as plt
    from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
    from numpy.polynomial.polynomial import Polynomial
    from scipy.interpolate import BSpline
    from scipy.interpolate import interp1d
    Time=[0.1,0.5,1,5,10,50,100,250,500,1000,2500,5000]
    Intensity=[2722.164194,2877.627742,2663.520645,2708.928125,2545.461613,2421.236129,1885.837742,1710.483871,1275.428387,776.0895806,192.4806452,26.35279]
    fun = interp1d(x=Time, y=Intensity, kind=2,bounds_error=False)
    x2 = np.linspace(start=-0.1, stop=5000, num=100000)
    y2 = fun(x2)
    fig, ax = plt.subplots()
    ax.scatter(Time, Intensity)
    ax.plot(x2,y2, color="r")
    ax.xaxis.set_major_locator(MultipleLocator(500))
    ax.xaxis.set_minor_locator(MultipleLocator(100))
    ax.yaxis.set_major_locator(MultipleLocator(500))
    ax.yaxis.set_minor_locator(MultipleLocator(100))
    ax.set_xlabel("Trapping time (ms)")
    ax.set_ylabel("Average Intensity (counts/s)")

    Continue reading...

Compartilhe esta Página