How to plot an image using the data set

Good afternoon. I am new to pygmt and I donot have more idea on how to plot the image something similar to this Screenshot from 2022-12-08 16-47-41 using the data set provided here Send large files up to 5GB for free

I hope experts may help me overcoming this problem.
Thanks in advance.

Could you share the first lines of your data file please?

it looks like this
-5.241162737805681366e-06
-1.219235276324636313e-05
-1.562016048517405562e-05
-1.506173518941282077e-05

A single column??

no data consists of 1500 rows and 512 columns or u can get the data from here https://transfer.pcloud.com/download.html?code=5ZTvhsVZD5tA3pjvqSLZri6IZ8pdgP4189iXHjBI0ePghljTWf7jX

mmm, it looks to me like a grid format but without header.

yes u r right.

If your data is a grid, them you could use grdimage directly.
If your data is a table, them yoiu have to use xyz2grd first (and them grdimage).

can you please share an example, how to do it.

The xyz2grd manual has several examples.

The data file is missing labels and units, so not sure how to interpret the numbers, but this should give you a start:

import numpy as np
import pygmt
import xarray as xr

# Load 2D data
array = np.loadtxt(fname="data.txt")
assert array.shape == (750, 1500)

# Convert numpy.array to xarray.DataArray
dataarray = xr.DataArray(data=array)

# Plot figure
fig = pygmt.Figure()
fig.grdimage(
    grid=dataarray, cmap="batlow", frame=["xaf+lTime [sec]", "yaf+lFrequency [Hz]"]
)
fig.colorbar(position="JMR")
fig.savefig(fname="freq_over_time.png")
fig.show()

gives

1 Like

Thank you @weiji14 for providing the demo.