Gmt plot not appearing on map [pygmt]

Hey,

I wanted to plot squares on a map at location longitude and latitude of my input file and the color should be based of a value to corresponding coordinates. I got this working almost 1:1 the same way with other files, but now it does not seem to work, because I only get the basemap, but not the coloured triangles on it. Colorbar is showing the correct values (from -3 to 6)… Maybe I’m missing something obvious but I just copied the script and fitted it to the new files. :worried: I don’t get any error messages, just empty Italy plots for each input file I loop.

import pygmt
import numpy as np
import math
import pandas as pd
import glob


#dataframe = pd.read_csv('Italy_E086.txt', header=0, names=['Lon', 'Lat', 'pval_score', 'gamma_score', 'beta_score', 'zeta_score', 'p2_score','t2_score', 'sum_score'])

filenames = glob.glob("Italy_E0*")
filenames = sorted(glob.glob("*csv"))
events = [pd.read_csv(filename,header=0, names=['Lon', 'Lat', 'pval_score', 'gamma_score', 'beta_score', 'zeta_score', 'p2_score','t2_score', 'sum_score']) for filename in filenames]
for dataframe, filename in zip(events, filenames):
  dataframe['filename'] = filename
for dataframe, filename in zip(events, filenames):
    name = filename.rstrip('.csv')
    fig = pygmt.Figure()
    fig.coast(
        # Sets the x-range from 10E to 20E and the y-range to 35N to 45N
        region="5/20/34/49",
        # Set projection to Mercator, and the figure size to 15 centimeters
        projection="M15c",
        # Set the color of the land to light gray
        land="white",
        # Set the color of the water to white
        water="lightblue",
        # Display the national borders and set the pen thickness to 0.5p
        borders="1/0.5p",
        # Display the shorelines and set the pen thickness to 0.5p
        shorelines="1/0.5p",
        # Set the frame to display annotations and gridlines
        frame=["WSne", "xafg0.5+lx-axis", "yafg0.5+ly-axis"],
        resolution='h')
    gridsize = np.full(
        shape=len(dataframe['Lat']),
        fill_value=0.7)
    ### plot sum thresholds
    pygmt.makecpt(cmap="roma", reverse=True, series=[dataframe['sum_score'].min(), dataframe['sum_score'].max(), 1])
    fig.plot(
        x=dataframe['Lon'],
        y=dataframe['Lat'],
        size=gridsize,
        color=dataframe['sum_score'],
        cmap=True,
        style="sc",
        pen="black")
    fig.text(
        x=dataframe['Lon'],
        y=dataframe['Lat'],
        text=dataframe['sum_score'],
        font='6p,black')
    fig.colorbar(frame='af+l"sum_thresholds"')
    fig.savefig(f"{name}.png", dpi=600)

Have you inspected dataframe ['Lon'], dataframe['Lat'], and dataframe['sum_score'] for an iteration to make sure that there are values in those columns and that the longitude and latitude are within your region?

Hey, thanks for your answer. Yes, I tested it and prints also the correct values.

Meanwhile I ‘solved’ it. Problem was the header line of the file, although I correctly assigned them and as I said, they were printed out correctly when called. Now it works, when I define the header=None, and then skiprows=1 with pandas.read_csv…
I don’t know why it was a problem but now it works, but instead I have to index the columns now with numbers and can’t use the ehader anymore.