Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in a column to plot for error_bars #735

Open
weiji14 opened this issue Dec 15, 2020 · 2 comments
Open

Allow passing in a column to plot for error_bars #735

weiji14 opened this issue Dec 15, 2020 · 2 comments
Labels
enhancement Improving an existing feature help wanted Helping hands are appreciated

Comments

@weiji14
Copy link
Member

weiji14 commented Dec 15, 2020

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 #666 (comment)

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 weiji14 added enhancement Improving an existing feature help wanted Helping hands are appreciated labels Dec 15, 2020
@weiji14
Copy link
Member Author

weiji14 commented Feb 16, 2021

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

pygmt/pygmt/src/plot.py

Lines 207 to 213 in 65b099a

if "G" in kwargs and not isinstance(kwargs["G"], str):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for color if data is matrix or file."
)
extra_arrays.append(kwargs["G"])
del kwargs["G"]

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
Copy link
Member

seisman commented Feb 16, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature help wanted Helping hands are appreciated
Projects
None yet
Development

No branches or pull requests

2 participants