Pygmt drawing errorbar

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

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

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:

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()


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 :slightly_smiling_face::

```
your script formatted as code
```

amazing! Thank you so much.

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

Cheeers,
MN