# Legend symbol mismatch for hachured pattern in PyGMT

**URL:** <https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372>\
**Category:** PyGMT Q&A\
**Created:** [October 24, 2023, 2:15pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372 "2023-10-24T14:15:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robson](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Robson](https://forum.generic-mapping-tools.org/u/Robson)\
**Post date:** [October 24, 2023, 2:15pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372/1 "2023-10-24T14:15:59Z")

</div>

I’m currently working on a map using PyGMT, and I’ve encountered an issue when trying to insert a legend for a hachured symbol. The problem is that the legend symbol does not match the hachure pattern I’ve defined in the map. I’m looking for some guidance on how to resolve this discrepancy. Here’s an example of the problem:

```
import pygmt

fig = pygmt.Figure()
fig.basemap(
region=[0, 5, 0, 5],
projection="X10c",
frame="rlbt+glightgray",)

fig.plot(
x=2.5,
y=2.5,
style="c1c", 
pen="1p,red", 
fill="p8+fred+b-", label='hachure')

fig.legend(box=False, position='+o0.5c')

fig.show()

```

 ![Example_figure](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/80a3e351f663e49537d761a34e6f50d133e34851.png)

---

<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:** [October 24, 2023, 2:52pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372/2 "2023-10-24T14:52:15Z")

</div>

Same in GMT CLI so we have ourselves a bug! Looks like it ignores the b- indication for the legend.

---

<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:** [October 24, 2023, 4:20pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372/3 "2023-10-24T16:20:27Z")

</div>

Hello @Robson,

when using the `label` parameter of `Figure.plot` and adding an auto-legend, the modifiers `+f` and `+b` to adjust the color of the pattern seem to be ignored, as mentioned by @pwessel. But when using an external GMT specific legend file and passing it the `spec` parameter of `Figure.legend` the legend entry is correctly added:

I just modified and extended your code example to test this:

Legend file (please place it in your working directory): [legend\_pattern.txt](https://forum.generic-mapping-tools.org/uploads/short-url/TcK7bCOh7NkOMFBC8vrrhlyCWC.txt) (195 Bytes)

```python
import pygmt

fig = pygmt.Figure()

# -----------------------------------------------------------------------------
# Left: auto-legend via label parameter
fig.basemap(
    region=[0, 5, 0, 5],
    projection="X10c",
    frame="rlbt+tauto-legend via label +glightgray",
)
fig.plot(
    x=2.5,
    y=2.5,
    style="c1c", 
    pen="1p,red", 
    fill="p8+fred+b",
    label="fill hachure colored",
)
fig.legend(box=False)

fig.shift_origin(xshift="+w0.5c")

# -----------------------------------------------------------------------------
# Right: manual legend via external file passed to spec parameter
fig.basemap(
    region=[0, 5, 0, 5],
    projection="X10c",
    frame="rlbt+tmanual legend via spec+glightgray",
)
fig.plot(
    x=2.5,
    y=2.5,
    style="c1c", 
    pen="1p,red", 
    fill="p8+fred+b",
)

fig.legend(spec="legend_pattern.txt", box=False)

fig.show()
# fig.savefig(fname="legend_pattern.png")

```

_Output figure_:

 ![legend_pattern](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/c/c5d99feccda1f398652dd8809ba126d3a3cc428f.png)

---

<div class="post-metadata">

**Author:** ![Robson](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Robson](https://forum.generic-mapping-tools.org/u/Robson)\
**Post date:** [October 24, 2023, 4:31pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372/4 "2023-10-24T16:31:42Z")

</div>

@yvonnefroehlich Thank you very much, I will mark your answer with the workaround using the specifications file as a solution.

---

<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:** [October 24, 2023, 9:24pm UTC](https://forum.generic-mapping-tools.org/t/legend-symbol-mismatch-for-hachured-pattern-in-pygmt/4372/5 "2023-10-24T21:24:34Z")

</div>

Bug found and fixed in this [PR](https://github.com/GenericMappingTools/gmt/pull/7973). Expect approval and merging into master soon. Thanks for pointing this problem out!
