# Fixed width and height frame

**URL:** <https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770>\
**Category:** PyGMT Q&A\
**Created:** [March 20, 2023, 4:31am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770 "2023-03-20T04:31:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 4:31am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/1 "2023-03-20T04:31:02Z")

</div>

Can we fixed widht and height frame like arcgis? So, if region larger or smaller, widht frame dont change

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [March 20, 2023, 8:03am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/2 "2023-03-20T08:03:39Z")

</div>

Do you mean the region (`-R`) or the dimensions (`-J`) of the plot?  
For the latter, see e.g. [6. GMT Map Projections](https://docs.generic-mapping-tools.org/dev/cookbook/map-projections.html#gmt-map-projections);

- (detault is **+dw** )
- Append **+dh** to the given [dimension](https://docs.generic-mapping-tools.org/dev/cookbook/features.html#dimension-units) to specify map _height_.
- Append **+du** to the given [dimension](https://docs.generic-mapping-tools.org/dev/cookbook/features.html#dimension-units) to select the minimum map dimension.
- Append **+dl** to the given [dimension](https://docs.generic-mapping-tools.org/dev/cookbook/features.html#dimension-units) to select the maximum map dimension.

---

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 8:17am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/3 "2023-03-20T08:17:38Z")

</div>

I have boundary region, like lonmin/lonmax/latmin/latmax. How to fix width and heigh to draw in canvas. Because, if we draw different boundary (larger or smaller), widht and height do change

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [March 20, 2023, 8:34am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/4 "2023-03-20T08:34:30Z")

</div>

Sounds like you’re using _scale_ instead of _width_ [default], e.g. `-Js` and `-JS` respectively.

Need to see some code to be able to help more.

---

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 8:41am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/5 "2023-03-20T08:41:14Z")

</div>

This is a piece of my code. So, i want to read boundary from input data. So, I have dynamic area. I want to plot with grdimage in my canvas with widht 26 and height 11.5. How to do that?

latmin = df[(df[9] == df[9].min())]  
latmax = df[(df[9] == df[9].max())]  
lonmin = df[(df[10] == df[10].min())]  
lonmax = df[(df[10] == df[10].max())]

region = [lonmin.iloc[0][11]-5, lonmax.iloc[0][11]+5, latmin.iloc[0][10]-5, latmax.iloc[0][10]+5]

fig.grdimage(grid=grid, cmap=“bati\_oceanworld.cpt”, yshift=“3.2c”, xshift="-0.4c", projection=“Q10i”, frame=[“ag”,“WSNE”, “xaf”], shading=“shading.grd.int”)

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [March 20, 2023, 8:52am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/6 "2023-03-20T08:52:38Z")

</div>

Sorry, I see now that this is PyGMT - I do not use that (yet), so I’m having trouble helping you.

---

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 8:54am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/7 "2023-03-20T08:54:43Z")

</div>

Dont worry, I will convert them to pygmt. In gmt, how to do that?

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [March 20, 2023, 9:14am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/8 "2023-03-20T09:14:32Z")

</div>

For a map of Denmark with the Mercator projection:

- fixed width (default, `+dw` is implicit): `$ gmt pscoast -RDK -W -Bafg -JM10c+dw -png dk`
- fixed height (`-dh`): `$ gmt pscoast -RDK -W -Bafg -JM10c+dh -png dk`

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [March 20, 2023, 9:14am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/9 "2023-03-20T09:14:41Z")

</div>

Hello @ankara17,

thanks for providing your code!

Based on my current understanding of your question, I feel what you want to do is not possible. If you state the width of the map together with the region and projection, the height of the map will be determined by these values and can not set be freely anymore.

---

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 9:41am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/10 "2023-03-20T09:41:51Z")

</div>

if I only use projection how to do that? So, the projection will approach widht and height

---

<div class="post-metadata">

**Author:** ![ankara17](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ankara17/32/4530_2.png) [@ankara17](https://forum.generic-mapping-tools.org/u/ankara17)\
**Post date:** [March 20, 2023, 9:51am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/11 "2023-03-20T09:51:24Z")

</div>

If I want to fixed widht and height, may I?

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [March 20, 2023, 11:44am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/12 "2023-03-20T11:44:34Z")

</div>

I don’t think you can do that with a projection.

If you have projected data, you could plot it as cartesian and force a width/height with e.g. `-JXwidth/height`, I think. But your plot may look ‘stretched’ by doing this.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [March 20, 2023, 11:46am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/13 "2023-03-20T11:46:37Z")

</div>

Other idea:

Plot your map with desired scale  
Overlay basemap with desired size  
Adjust the region to « fill » the blank spaces

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [March 20, 2023, 11:48am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-and-height-frame/3770/14 "2023-03-20T11:48:12Z")

</div>

Just to be clear, you want a fixed map dimensions (26 c x 11.5 c) and a approximate region (anyone that include all your data), right? Could you give us an example of the map that you want to make.

I think that [mapproject -W](https://docs.generic-mapping-tools.org/dev/mapproject.html#w) could help you.
