2

I am trying to plot things in matplotlib but plot function creates a graph with sudden changes despite the fact that in excel it looks smoother. i don't know the attribute so I will just call it 'squary'. The differences are show in the picture (top - matplotlib, bottom - excel).

figure = pyplot.figure();
for channel in channels:
    pyplot.plot(time[:len(channel)], channel);
pyplot.show();

The original data is not 'squary'. It is high-density data collected every 10 minutes for 67 days. The excel plot was not done with smoothing option. It was done with straight lines between successive data points confirming that the data is not 'squary' at all. I assume the problem is some parameter in the pyplot function that I don't know off.

I have realized that the problem was rounding to 2 decimals in Excel. Although the plot looks smooth in Excel when copying the data from the table, numbers were trimmed. Basically just set the rounding to more decimals and then the curve will look smooth in matplotlib as well.

enter image description here

DorinPopescu
  • 715
  • 6
  • 10
  • 1
    You may want to show your data, or at least dummy data. I guess your data is already "squary", as you call it. – cel Jul 07 '15 at 21:04
  • Excel has a "smoothing" option in its plotting tools. So I guess you ticked that? Also the excel graph has way thicker lines, this often also helps to make lines look a bit smoother. – hitzg Jul 08 '15 at 08:36
  • To clarify, the original data is not 'squary' because it is hight-density. only the output in matplotlib is squary and this is the problem. The present excel plot was not done with any smoothing option. It is done with straight lines. The smooth appearance is due to the data it-self which was collected every 10 minutes for 67 days. – DorinPopescu Jul 08 '15 at 09:03
  • Possible duplicate of [How to smooth a curve in the right way?](http://stackoverflow.com/questions/20618804/how-to-smooth-a-curve-in-the-right-way) – Serenity May 28 '16 at 07:51
  • No, this is not a problem of how to smooth data. – DorinPopescu May 30 '16 at 12:31

1 Answers1

1

I finally found the solution and it is not related to matplotlib but to Excel. I have realized that the problem was rounding to 2 decimals in Excel. Although the plot looks smooth in Excel when copying the data from the table, numbers were trimmed. Basically just set the rounding to more decimals and then the curve will look smooth in matplotlib as well.

So one should be careful to how the data will be affected after copy from Excel.

DorinPopescu
  • 715
  • 6
  • 10