2022-11-19

I need to make a scatter plot of Mass Spectrometry data on Python

The graph should look like this:

This is the plot I want:

But I got this graph instead, with the following error message: My current Plot

I'm getting this Pycharm message in red after running my program:

MatplotlibDeprecationWarning: The resize_event function was deprecated in Matplotlib 3.6 and will be removed two minor releases later. Use callbacks.process('resize_event', ResizeEvent(...)) instead.
  plt.title("Spectra")

How can I improve my graph to look like the one on top or like a real scatter plot?

Here's my code:

import matplotlib.pyplot as plt
import numpy as np
x = []
y = []
for line in open('Maldi', 'r'):
    lines = [i for i in line.split()]
    x.append(float(lines[0]))
    y.append(float(lines[1]))


plt.title("Spectra")
plt.xlabel('m/z')
plt.ylabel('Intensity')
plt.yticks(y)
plt.scatter(x, y, marker ='o', c ='black')
plt.show()

The data set is large. I'm not sure how to write a code that could graph a large date set with (x,y) coordinates that look like this (this is only a subset of the data):

498.178207  1.63399
498.359139 2.28758
498.540102 5.22876
498.721099 1.30719
498.902129 1.30719
499.083191 0.326797
499.264287 1.63399
499.445415 1.63399
499.626576 4.57516
499.807770 1.96078
499.988997 2.94118
500.170257 2.61438
500.351549 4.57516
500.532875 5.22876
500.714233 2.28758
500.895625 2.28758
501.077049 1.30719
501.258506 4.90196
501.439995 6.86275
501.621518 3.26797
501.803074 2.28758


No comments:

Post a Comment