Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix unit handling in errorbar for astropy. #19872

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

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3427,13 +3427,17 @@ def extract_err(name, err, data, lolims, uplims):
the note in the main docstring about this parameter's name.
"""
try:
low, high = np.broadcast_to(err, (2, len(data)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I looked at this so late. A simpler solution here is to add subok=True...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just today, I decided to look at how matplotlib does this, because I need a similar interface (accept a scalar and 1 d array or a 2 d array - just like err here. I guess that's a rare case that that happens, but should I open a PR to simplify this back to np.boradcast_to with subok?

np.broadcast_to(err, (2, len(data)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to check for this directly, rather than via an error? Maybe this is just as efficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... I guess I just mean int(len(err)/2)==len(err)/2, or whatever is more elegant than that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance should not matter. This should be proportional to len(data) in computation/mempry and is only called once twice for the whole errorbar function.

except ValueError:
raise ValueError(
f"'{name}err' (shape: {np.shape(err)}) must be a scalar "
f"or a 1D or (2, n) array-like whose shape matches "
f"'{name}' (shape: {np.shape(data)})") from None
return data - low * ~lolims, data + high * ~uplims # low, high
# This is like
# low, high = np.broadcast_to(...)
# return data - low * ~lolims, data + high * ~uplims
# except that broadcast_to would strip units.
return data + np.row_stack([-(1 - lolims), 1 - uplims]) * err

if xerr is not None:
left, right = extract_err('x', xerr, x, xlolims, xuplims)
Expand Down