# Two x axes in gmt

**URL:** <https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [February 18, 2022, 7:46am UTC](https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638 "2022-02-18T07:46:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyushether](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/piyushether/32/87_2.png) [@piyushether](https://forum.generic-mapping-tools.org/u/piyushether)\
**Post date:** [February 18, 2022, 7:46am UTC](https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638/1 "2022-02-18T07:46:05Z")

</div>

@pwessel @Joaquim

Hi,

I am surprised if one can make two x-axes in GMT. I tried with primary and secondary annotation options but it got confused in considering the inputs for both the axes. I attached the example plot below which I want to achieve. I am confused that how should I provide inputs for two x-axes.  
I want to plot longitude and latitude on two x-axes, height on the y-axis, and the parameter value as a colormap. In general, I was providing (lat/lon, height, parameter) as an input. For the case of two x-axes, I tried to provide (lat, lon, height, parameter) with primary and secondary x-axes with -B option.  
I am unable to achieve what I want. Do I need to write two different lines to make primary and secondary x-axes? In addition, If one can see the attached image the values of x-axes are not in order but it follows the flight path. First, it traveled to the south and come back to the north again. I think this will be solved once we can able to plot two x-axes. Am I correct?

 ![HSRL2-ext532_P3_20181017_R1](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a04962593039786fb309515a2d7d34054e72cbf2.png)

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 19, 2022, 11:59am UTC](https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638/2 "2022-02-19T11:59:13Z")

</div>

GMT has secondary annotations of x-axes but not a double axis. So yes, you’ll need to plot a secondary x-axes and use custom annotations for your case.

---

<div class="post-metadata">

**Author:** ![piyushether](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/piyushether/32/87_2.png) [@piyushether](https://forum.generic-mapping-tools.org/u/piyushether)\
**Post date:** [February 19, 2022, 10:36pm UTC](https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638/3 "2022-02-19T22:36:45Z")

</div>

Thanks, @Joaquim for the kind response. I tried that but it is not working out. As my parameter values are associated with lat, long, and altitude, I want to plot lat, long on the x-axis, and altitude on the y-axis. It means a parameter value has to be associated with these three parameters, but when I plot lat on one x-axis and separately long on the second x-axis at that time they are not connected and I couldn’t able to plot the whole flight path going and coming in a single curtain as I showed in the attached figure. Hope this makes sense.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 20, 2022, 12:44am UTC](https://forum.generic-mapping-tools.org/t/two-x-axes-in-gmt/2638/4 "2022-02-20T00:44:45Z")

</div>

Well, in a xy plot you cannot plot something depending on _lon, lat & altitude_ but you can compute the accumulated distance along that _lon, lat_ and make a plot _accum\_dist vs altitude_. And after you can compute a _dist from origin_ and use that to create a secondary axes in which you’ll use a custom axis annotations. Custom because normal axes settings must be monotonically increasing/decreasing and your going and return are not.
