How to read .png file with matplotlib to not lack information?

74 Views Asked by At

I have created a png file with matplotlib. When opened in a Viewer it shows all the parts of the graph. However, when reading the image with matplotlib, only the coordinate system is shown, not the bars.

I created the plot using spectrum_utils.

import spectrum_utils.plot as sup
import spectrum_utils.spectrum as sus

import matplotlib as plt

db_hit_spectrum = sus.MsmsSpectrum('9407', 200.2373, 1, [71.0852, 85.1012], [2, 1])
query_spectrum = sus.MsmsSpectrum('9407', 200.2372, 1, [71.0858, 85.1013, 98.9841], [13000000., 6700000., 850000.])

fig, ax_1 = plt.subplots(figsize=(12, 6))
ax_1.set_title(f"DB hit of N-Methyldodecylamine and query spectrum with ID 9407")
sup.mirror(query_spectrum, db_hit_spectrum, spectrum_kws={'grid': False})

fig.savefig("test.png")

a = plt.imread("test.png")
plt.imshow(a)

The picture this saves:

The picture I save

The picture shown after reading it back in:

The picture shown after reading

Also, when calling the spectrum_utils functions, I can get back the peaks, but I want to read the picture somewhere I do not have the information necessary.

Edit:

The picture after using plt.imshow(mpimg.imread('test.png'), aspect='auto'):

The picture after using aspect='auto'

When reading it back in, I now have the problem of a a picture in a picture.

0

There are 0 best solutions below