Issues with the plotting with pyGMT

Hello, I have to plot the map of the TMI and the TMI with RTP, but I’m having some issues with that. I simulated the survey and get the dpred (tmi_data) and the data with RTP (tmi_rtp).

Im using this code to try to plot the maps:

import pygmt
import numpy as np
# Definir las coordenadas x e y
x = np.linspace(-80.0, 80.0, 17)
y = np.linspace(-80.0, 80.0, 17)

# Crear un objeto Grid a partir de los datos magnéticos
grid_data = pygmt.datasets.Grid.from_array(x=x, y=y, data=tmi_data)

fig = pygmt.Figure()
with fig.subplot(nrows=1, ncols=2, figsize=("28c", "15c"), sharey="l"):
    # Make colormap for both plots (saturate it a little bit)
    scale = 0.5 * vd.maxabs(tmi_data, tmi_rtp)
    pygmt.makecpt(cmap="polar+h", series=[-scale, scale], background=True)
    with fig.set_panel(panel=0):
        # Plot magnetic anomaly grid
        fig.grdimage(
            grid=grid_data,
            cmap=True,
        )
        # Add colorbar
        fig.colorbar(
            frame='af+l"Magnetic anomaly [nT]"',
            position="JBC+h+o0/1c+e",
        )
    with fig.set_panel(panel=1):
        # Plot upward reduced to the pole grid
        fig.grdimage(grid=tmi_rtp, cmap=True)
        # Add colorbar
        fig.colorbar(
            frame='af+l"Reduced to the pole [nT]"',
            position="JBC+h+o0/1c+e",
        )
fig.show()

But it is showing me: "AttributeError: module ‘pygmt.datasets’ has no attribute ‘Grid’.

Thanks in advance.

Hello @unatalfrench,

Currently, it appears difficult to help you.
Can you please provide more information regarding your data tmi_data? It looks like you never defined this variable in your code example.

Based on

# Crear un objeto Grid a partir de los datos magnéticos
grid_data = pygmt.datasets.Grid.from_array(x=x, y=y, data=tmi_data)

it looks like you want to set up a grid from tabular data which can be used in PyGMT. For this you may want to use pygmt.xyz2grd.

pygmt.datasets provides easy access to the GMT (remote) datasets and loads them into a xarray Data.Array for further processing and visualization.