I am using Python 3.8
, Matplotlib 3.2.2
and Scipy 1.5.0
. I am new to Matplotlib and Pandas, but am getting there.
I have some meterological data in a Pandas Dataframe and I can draw a graph of 24hrs of Barometric Pressure and Rain against Time every 5 mins on the x axis.
I would like to smooth the Pressure Curve, but cannot get it to work.
I have looked at the tutorial here and here and also looked at this question amongst others.
Here is the unsmoothed graph:
Plot of Barometric Pressure and Rain against Time:
and the code:
-------- snip --------
ax_graph_pressure.plot(x, y, linewidth=0.5, color='#C00000')
ax_graph_rain.bar(x, z, width=0.002, color='#FF0000')
ax_graph_pressure.grid(which='major', axis='y')
-------- snip --------
plt.show(dpi=96)
x is a Datetimeindex array from the df.index of the Pandas Dataframe and y is an array of Floats for Pressure and z in an array of floats for Rain. I have tried this from the tutorials above:
-------- snip --------
unix_time = []
# convert to Unix timestamp
for xx in df.index:
unix_time.append(xx.replace(tzinfo=timezone.utc).timestamp())
xnew = np.linspace(unix_time[0], unix_time[len(unix_time) - 1], num = 576, endpoint=True)
f2 = interp1d(unix_time, y, kind='cubic')
ax_graph_pressure.plot(xnew, f2(xnew), linewidth=0.5, color='#C00000')
ax_graph_rain.bar(x, z, width=0.002, color='#FF0000')
ax_graph_pressure.grid(which='major', axis='y')
-------- snip --------
plt.show(dpi=96)
I had to convert the time in x to UnixTime or I get an error, I also double the number if items to smooth the curve. When I do this the graph does not appear even after a long wait (more than 10 mins). It gets stuck at the plt.show stage. Normally the graphs appears very quickly. Any help would be much appreciated.