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

A single column??

no data consists of 1500 rows and 512 columns or u can get the data from here

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()
    grid=dataarray, cmap="batlow", frame=["xaf+lTime [sec]", "yaf+lFrequency [Hz]"]


1 Like

Thank you @weiji14 for providing the demo.