# Is there an -i option for plot -Z?

**URL:** <https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720>\
**Category:** Q&A\
**Created:** [May 24, 2021, 7:21pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720 "2021-05-24T19:21:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [May 24, 2021, 7:21pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/1 "2021-05-24T19:21:58Z")

</div>

I’m trying to color a multisegment line with a CPT according to the point’s z-value. My data looks like this:

```
                      z-values lat lon
                          | | |
                          V V V
1620802958 3C65D9 DLH008 650 142 -110.605 50.0381 8.55761 2880 5024 A
1620802959 3C65D9 DLH008 650 142 -110.605 50.0381 8.55761 2880 5024 A
1620802959 3C65D9 DLH008 750 141 -110.748 50.0377 8.5559 2880 5024 A
…

```

I tried `plot flight.txt -i7,6 -W+z -Zflight.txt` but only got an error as my z-values aren’t in the last colum as required per [`plot -Z`](https://docs.generic-mapping-tools.org/latest/plot.html#z) documenation. Is there something similar to the `-i` option for `plot -Z` I’m missing?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [May 24, 2021, 7:34pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/2 "2021-05-24T19:34:37Z")

</div>

Sorry, violation of the GMT record directive: All numerical columns first, then all trailing text. Your 3C65… etc starts the trailing text.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [May 24, 2021, 7:37pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/3 "2021-05-24T19:37:08Z")

</div>

awk ‘{print($8,$7,$4)}’ …

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [May 24, 2021, 7:58pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/4 "2021-05-24T19:58:58Z")

</div>

Hi @pwessel I’m not sure I understand your point: When I use `plot flight.txt -i7,6 -W1p,red` everything works as expected. Z-values are treated as trailing text?

Hi @thwbecker – I hoped to get around rearranging the columns (in total about 856 GB worth of data). But your `awk` snippet does the trick nicely on my test data set. Thank you.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [May 24, 2021, 8:05pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/5 "2021-05-24T20:05:19Z")

</div>

I see GMT converts your columns 2 and 3 to NaN so you are able to use -i7,6. OK, I suspect a bug since -Z is relatively recent and I bet there is interference with -i. We have seen that before and addressed it but probably not here. Might you be able to produce a command plus a Z file that uses the three lines above in an attempt to do your plot and that gives that error?

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [May 24, 2021, 8:48pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/6 "2021-05-24T20:48:21Z")

</div>

I should have made some example code available right away. My apologies, @pwessel. Here is a bare bones version:

```
gmt begin deps_eddf png
  gmt plot -R007:30/010:00/49:30/50:50 \
    -JL008:34:13.64/50:01:59.90/49:57/50:23/15c -B \ 
    flight.txt -i7,6 -W1p,red
gmt end show

```

[flight.zip](https://forum.generic-mapping-tools.org/uploads/short-url/hoivDMjQrqWmQ0YOzD6WiFxotuS.zip) (3.2 KB) contains the required `flight.txt`

This works as expected. I get a red line on the plot.

 ![airspace_eddf](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/9/9aea0bb0f443237afb61e2407fa1e5b0f15e187d.png)

Now for what I’m trying to achieve: Column 3 (when you start counting at 0) contains my z-values, in this case altitude information. I want to color the plotted line according to altitude with a CPT. In my understanding this can be done with `-W+z -Zflight.txt -Cbuda`. But only if the supplied file has the z-values in the last column:

> Alternatively, give the name of a _file_ with one z-value (read from the last column) for each polygon in the input data.

[(source)](https://docs.generic-mapping-tools.org/latest/plot.html#z)

So recycling my data file fails predictably:

```
gmt begin deps_eddf png
  gmt plot -R007:30/010:00/49:30/50:50 \
    -JL008:34:13.64/50:01:59.90/49:57/50:23/15c -B \
    flight.txt -i7,6 -W+z -Zflight.txt -Cbuda
gmt end show

```

This code seems to wait for input which never comes and needs to be terminated.

I tried `-i7,6,3` as a moonshot but got no luck:

`plot [WARNING]: Number of input columns required [2] is less that implied by -i [3]`

I assume this is the polygon plotting machinery complaining.

It all boils down to the question: Is there a way to get those z-values from my original data without preparing a separate file for `-Z`?

I have around 4700 tracks to plot adding up to about 856 GB of ASCII-data. Or would you say it is more efficient to crunch the data into specialized files?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [May 24, 2021, 10:00pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/7 "2021-05-24T22:00:36Z")

</div>

A workaround for now is to make a copy of flight.txt, say flight2.txt and use that in -Z and then it works. I will debug why it wont release that pointer…You are using the same file for two different inputs and for some reason that hangs.

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [May 24, 2021, 10:49pm UTC](https://forum.generic-mapping-tools.org/t/is-there-an-i-option-for-plot-z/1720/8 "2021-05-24T22:49:52Z")

</div>

Thank you for looking into this @pwessel!
