I am trying to create a scatter plot from instrument peak area data recorded every tenth of a second or so. For some reason, when I try to plot it with Matplotlib, I get a straight line, which is not at all representative of the data. I feel it may be a syntax error, but I cannot figure it out. I've worked with a few tutorials, and they generally give me the same results, so I am thinking it must be an error in my graphing method.

Here is what I have so far:

import matplotlib.pyplot as plt
import numpy as np 
fig = plt.figure()
x = new_df.tIn
y = new_df.In
ax = fig.add_subplot()
fig.suptitle("What is going on?", fontweight ="bold")  

And this is the figure I get, which neither reflects my data or the tick marks I was trying to display: Resulting image

Does anyone see what I am doing wrong? Does it have to do with the 'In' having so many decimal places? Thanks in advance!

For reference here is the format of data I am working from:

enter image description here

  • 1
    $\begingroup$ To get a scatter plot you might want to try using ax.scatter instead of ax.plot. $\endgroup$
    – Oxbowerce
    Oct 26, 2022 at 7:57
  • $\begingroup$ Good idea! I tried this and it resulted in the same trend though, with larger marker points. $\endgroup$ Oct 26, 2022 at 16:21
  • $\begingroup$ Have you tried drawing it with other modules like seaborn? Was the result the same? What's that number specified on y-axis? $\endgroup$
    – Miss.Alpha
    Oct 26, 2022 at 19:34
  • $\begingroup$ @Miss.Alpha I have, I tried it as follows: ax = sns.scatterplot(x=df.tIn, y=df.In, data = new_df, color='steelblue') ax.set(xlabel='Time (s)', ylabel='Peak Intensity (CPS)', title='LCICPMS Results') plt.show() and it resulted the same. The random number on the y axis it generated on it's own based on what I put in for ax.yaxis.set_ticks([2000,3000]) which doesn't match what I put either. I have been successful with a smaller dataset, so it is confusing it is having trouble with 2640 points... compared to other plots I have seen that isn't that much data $\endgroup$ Oct 27, 2022 at 0:28
  • 1
    $\begingroup$ That's great that you found a solution to your problem. If you think your answer can help somebody else submit your answer. $\endgroup$
    – Miss.Alpha
    Oct 29, 2022 at 14:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.