Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

python - How to improve the Smoothness (steepness) of the curve using matplotlib?

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
ight)$')
plt.ylabel('Temperature' + r'$left(C
ight)$')

# 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
question from:https://stackoverflow.com/questions/65841287/how-to-improve-the-smoothness-steepness-of-the-curve-using-matplotlib

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...