# Cross-Section Depth colors

**URL:** <https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605>\
**Category:** PyGMT Q&A\
**Created:** [January 12, 2023, 4:25am UTC](https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605 "2023-01-12T04:25:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [January 12, 2023, 4:25am UTC](https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605/1 "2023-01-12T04:25:13Z")

</div>

Dear All,

I was trying to draw the cross-section profile circles with colors according to depth. So far I use the `pygmt.project` command to obtain the `cross.out` file

I wanted to use this file (`cross.out`) with `pygmt.makecpt` command in order to have a CPT palette, until here no problems.

I tried to apply the following command:

```
fig.plot(data="/home/asus/Documents/Pdoc_res/Catas/cross.dat", 
         cmap=True, color=df_cross.Depth, projection="X", style="cc", 
         pen='0.5p,black')

```

However, I obtained the following error:

`GMTInvalidInput: Can't use arrays for color if data is matrix or file.`

Does anyone obtained this error?, is it possible to create a color palette for the cross-section depth profile and plot them?, just in case I add my `cross.dat` file

Thanks in advance.  
[cross.dat](https://forum.generic-mapping-tools.org/uploads/short-url/tzKk4QrNFH0vdORO9IJ8dPsxnJ2.dat) (6.6 KB)

Tonino

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [January 15, 2023, 4:04am UTC](https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605/2 "2023-01-15T04:04:42Z")

</div>

I think PyGMT wants to have all the attributes for a plot in the same data frame or file. It looks like you already read the depth into the `df_cross` data array or data frame. Do you have the distance field of the `cross.dat` in the same data frame? Then you can use that in the plot command instead instead of the file.

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [January 16, 2023, 1:18am UTC](https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605/3 "2023-01-16T01:18:31Z")

</div>

@EJFielding, thank you for the answer, however, I am not sure if you refer this part of the code in which I create teh `cross.dat` file and in which I think the first column is the distance

```
pygmt.project(
    data="/home/asus/Documents/Pdoc_res/Catas/Input_GMT_profile_May_To_Sept_2022_POB.csv",
    unit=True,
    center=[-66.74, -17.57], 
    endpoint=[-65.52, -17.10],
    convention="pz",
    width=[-100, 100],
    outfile="/home/asus/Documents/Pdoc_res/Catas/cross.dat",
)
fig.basemap(
    projection="X10/-6",
    region=[-5, 240, -5, 50],
    frame=['xafg50+l"Distance"', 'yafg25+l"Depth"', "WSen"],
    yshift=-7,
)

```

Should I change some part of the code to get the distances?,  
Thanks in advance.

Tonino

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [January 16, 2023, 1:53am UTC](https://forum.generic-mapping-tools.org/t/cross-section-depth-colors/3605/4 "2023-01-16T01:53:42Z")

</div>

Yes, instead of using `pygmt.project` to read in the CSV file and put the output into the outfile “cross.dat”, you can read the CSV file into a dataframe and have the output go into another dataframe that will have the distance and depth values. Or, if you want to keep the outfile, then you can read the “cross.dat” file into a dataframe or array. Either way, you end up with the projected data in a single array or dataframe that you can send to `fig.plot`.
