GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
758 stars 220 forks source link

Allow passing in a column to plot for error_bars #735

Open weiji14 opened 3 years ago

weiji14 commented 3 years ago

The pygmt.fig.plot method has an error_bar (E) argument that isn't very usable right now. Ideally we would be able to pass in a list or numpy array of error values (e.g. standard deviation).

As agreed above, we'll figure out how to pass in an 'error' column with error_bars (E) and rename 'sizes' to 'size' in a separate PR next time.

Originally posted by @weiji14 in https://github.com/GenericMappingTools/pygmt/issues/666#issuecomment-716084019

There's also a Python package called uncertainties at https://github.com/lebigot/uncertainties/ which wraps error values around numpy arrays, it might be cool if we can integrate that with pygmt somehow! I.e. pass in an uncertainty array to fig.plot() and have it plot the error bars directly. Also could tie this in with the pint package at https://github.com/hgrecco/pint which has a concept of "Measurements" that includes the error with numbers.

weiji14 commented 3 years ago

Just as a follow because there's a related post on the forum (https://forum.generic-mapping-tools.org/t/pygmt-plot-errorbars), what we could do is to copy and modify these lines

https://github.com/GenericMappingTools/pygmt/blob/65b099a5873b4f9e76d7fccdbc8882d9b37870e3/pygmt/src/plot.py#L207-L213

to use kwargs["E"] instead of kwargs["G"], or maybe turn it into a for-loop over ("G", "E"). That way, passing an array into error_bars (E) should work, but I haven't tested it.

seisman commented 3 years ago

Just a quick note. The order of the data columns is important. For error bars,

The x and/or y errors must be stored in the columns after the (x,y) pair [or (x,y,z) triplet]

Refer to https://docs.generic-mapping-tools.org/dev/plot#e for details.