# Pygmt drawing errorbar

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-drawing-errorbar/5468>\
**Category:** PyGMT Q&A\
**Created:** [October 17, 2024, 11:43pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-drawing-errorbar/5468 "2024-10-17T23:43:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![muhammetnergizci](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/muhammetnergizci/32/2086_2.png) [@muhammetnergizci](https://forum.generic-mapping-tools.org/u/muhammetnergizci)\
**Post date:** [October 17, 2024, 11:43pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-drawing-errorbar/5468/1 "2024-10-17T23:43:06Z")

</div>

Hi, I would like to draw the errorbar in pygmt. I fundamentally use fig.plot as below but I can’t find how to put the error bars in y axis:

# Plot error bars for slip\_disp78 data

fig.plot(  
x=slip\_disp78[‘distance’],  
y=slip\_disp78[‘motion’],  
pen=“0.5p,blue”,  
style=“c0.2c”,  
fill=“blue”,  
error\_bar=“+y5p”, # Vertical error bars (sigma values)  
)

fig.plot(  
x=slip\_disp78[‘distance’],  
y=slip\_disp78[‘motion’],  
pen=“0.5p,blue”,  
)

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

the dataset looks like below:

| | distance | x | y | motion | y-error |
| --- | --- | --- | --- | --- | --- |
| 0 | 0.0 | 36.165 | 36.139 | 0.877 | 0.249 |
| 1 | 10.0 | 36.214 | 36.278 | 2.231 | 1.018 |
| 2 | 20.0 | 36.235 | 36.333 | 1.908 | 0.642 |
| 3 | 30.0 | 36.300 | 36.442 | 3.646 | 0.784 |
| 4 | 40.0 | 36.368 | 36.523 | 1.862 | 0.536 |
| 5 | 50.0 | 36.387 | 36.598 | 1.962 | 0.662 |
| 6 | 60.0 | 36.339 | 36.487 | 2.629 | 0.597 |
| 7 | 70.0 | 36.467 | 36.709 | 3.367 | 0.548 |
| 8 | 80.0 | 36.506 | 36.794 | 3.268 | 0.820 |
| 9 | 90.0 | 36.554 | 36.892 | 3.011 | 1.310 |
| 10 | 100.0 | 36.589 | 36.975 | 3.567 | 1.236 |
| 11 | 110.0 | 36.633 | 37.074 | 4.160 | 0.930 |
| … | | | | | |

---

<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 18, 2024, 9:26am UTC](https://forum.generic-mapping-tools.org/t/pygmt-drawing-errorbar/5468/2 "2024-10-18T09:26:57Z")

</div>

Hello @muhammetnergizci,

Besides the columns with x and y values, you have to provide the column with the y error. One way to do this is to read your data into a `pandas.DataFrame` and select the corresponding columns:

```python
import pygmt
import pandas as pd

# Please adjust file name and seperator (sep) to what you are using
data_yerror = pd.read_csv("data_with_yerror.txt", sep=" ")

fig = pygmt.Figure()

fig.basemap(region=[-10, 120, 0, 6], projection="X10c/5c", frame=True)
fig.plot(
    # Select columns for x, y and y error
   # Columns order after https://docs.generic-mapping-tools.org/6.5/plot.html#e
    data=data_yerror[["distance", "motion", "y-error"]],
    style="c0.1c",
    fill="blue",
    error_bar="y", # Plot error bars in y (vertical) direction only
)

fig.show()

```

 ![errorbars_ydir](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/b/b82f486d151698711c0d2512bee4c27cae5ccae7.png)

* * *

_A tip for next time posting_:

You can format your script as code by placing three backticks in the line before and after the block with the script 🙂:

````auto
```
your script formatted as code
```

````

---

<div class="post-metadata">

**Author:** ![muhammetnergizci](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/muhammetnergizci/32/2086_2.png) [@muhammetnergizci](https://forum.generic-mapping-tools.org/u/muhammetnergizci)\
**Post date:** [October 18, 2024, 11:57am UTC](https://forum.generic-mapping-tools.org/t/pygmt-drawing-errorbar/5468/3 "2024-10-18T11:57:12Z")

</div>

> [@yvonnefroehlich](#):
>
> ```auto
> fig.plot(
> # Select columns for x, y and y error
> # Columns order after https://docs.generic-mapping-tools.org/6.5/plot.html#e
> data=data_yerror[["distance", "motion", "y-error"]],
> style="c0.1c",
> fill="blue",
> error_bar="y", # Plot error bars in y (vertical) direction only
> )
> 
> ```

amazing! Thank you so much.

Yeah, I will ask next question in better format next time!

Cheeers,  
MN
