-1

In an experiment I conducted, I gathered the temperature data every 2 seconds. The experiment lasted over 3000s.

I tried plotting my findings with matplotlib with this sample code, after previously having imported each csv column into separate lists.

plt.plot(time, temperature)

plt.xlabel('Time' + r'$\left(s\right)$')
plt.ylabel('Temperature' + r'$\left(C\right)$')

# plt.xticks(np.arange(0, 3500, 500.0))
# plt.yticks(np.arange(0, 20, 2))

# plt.style.use('fivethirtyeight')
plt.show()


My result is this:

Graph

How can I improve this:

  • in order to make it smoother (maybe be experiment design - every 1 seconds data collection)
  • in order to make it more scientific (adding legend and writing celsius symbol instead of C for temperature units)

Any other helpful suggestions are welcome.

Edit: Sample Data

Time,Temperature
0,19.77317518
2,19.77317518
4,19.77317518
6,19.77317518
8,19.77317518
10,19.77317518
12,19.77317518
14,19.77317518
16,19.77317518
18,19.77317518
...
40,19.36848822
42,19.36848822
44,20.379735
46,20.17760174
48,20.379735
nocomment
  • 119
  • 6
  • 1
    It looks like the steps are artifacts of your data. Could it be that there are always two data points per time step, a higher and a lower one? Maybe post the first few elements of `time` and `temperature`? – tilman151 Jan 22 '21 at 08:10
  • In general, if you are trying to make the data smooth, the problem is called nonparametric regression. One possible, simple way is a smoothing spline, or LOESS. More sophisticated methods include wavelet smoothing and trend filtering. If you just want something quick-n-dirty, start with (centered) moving average or the smoothing spline. – Niko Föhr Jan 22 '21 at 08:11
  • @tilman151 Hey, thanks for taking a look. I've included the sample data in the question. – nocomment Jan 22 '21 at 08:41

1 Answers1

0

In order to add Celcius to y label:

plt.ylabel('Temperature ($^\circ$C)')

In order to smooth it, you should first use only markers

plt.plot(time, temperature, '.')

Matplotlib perform linear interpolation between 2 points this is why you have those "jumps"

If you want to fit a smooth line to the data check the following link:

How to smooth a curve in the right way?

David
  • 8,113
  • 2
  • 17
  • 36