8000 Add errorbars to mplot3d by vlas-sokolov · Pull Request #8031 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add errorbars to mplot3d #8031

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 36 commits into from
Aug 14, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66cbdf6
add minimal errorbar3d method to Axes3D
vlas-sokolov Jan 3, 2017
d8e4d57
for now it's wiser to rely on LineCollection styling
vlas-sokolov Jan 3, 2017
2d32dfe
type in autorange
vlas-sokolov Jan 3, 2017
8e66193
fix for auto-scaling NaN values
vlas-sokolov Jan 4, 2017
d377942
add caplines
vlas-sokolov Jan 5, 2017
9b1de1f
add barsabove option; refactor plotting kwargs
vlas-sokolov Jan 5, 2017
c7fc68a
fix for missing zorder in kwargs
vlas-sokolov Jan 5, 2017
ef5699c
add upper/lower limits
vlas-sokolov Feb 6, 2017
d4f67c2
add extended formatting from the 2d case; clean-up
vlas-sokolov Feb 6, 2017
3b3e5d4
pep8 edits
vlas-sokolov Feb 6, 2017
6889a3d
fix errorevery; return a container of sorts
vlas-sokolov Feb 7, 2017
20f0caf
allow offsets for errorevery
vlas-sokolov Feb 7, 2017
cd63593
arrrr pep8 again
vlas-sokolov Feb 7, 2017
fb2d200
docstring edits
vlas-sokolov Feb 9, 2017
74f5209
add example; update what's new section
vlas-sokolov Feb 9, 2017
82dec2b
please just squash everything - I can't pep8 properly
vlas-sokolov Feb 9, 2017
c570c69
vim adds a newline behind the scenes already
vlas-sokolov Feb 9, 2017
c30c276
rebase against current master + fix dropped deprecations
Apr 16, 2020
f5ef8bd
fix compatibility issues with 2d errorbar version (WIP)
Apr 17, 2020
c3fa542
fix flake8 warnings, mirror naming/docstring style of other examples
Apr 22, 2020
b86260a
fix failing sphinx docs
Apr 23, 2020
45cbc81
add an image comparison unit test for 3d errorbars
Apr 24, 2020
42c1d27
errline gets drawn when both limits are set (compat. reasons)
Apr 30, 2020
5969893
refactor to use art3d.get_dir_vector instead of np.roll
May 1, 2020
26a4226
adapt 2d errorbar containers for legend handling
May 6, 2020
c8f1161
need to consider everymask for altering upper=lower limits
May 6, 2020
e18713a
switch to plt.quiver for drawling arrows
May 13, 2020
159b6b5
refactor numpy array handling
May 13, 2020
5db6976
allow for (2, N)-shaped errorbar input + small numpy refactors
May 13, 2020
3c7c0de
add numpy refactor as per PR suggestion
vlas-sokolov May 14, 2020
3a99be8
add numpy refactror for errorbar3d example
vlas-sokolov May 20, 2020
1a6f58a
add numpy refactor for errorbar3d unit test
May 20, 2020
05f4776
Merge branch 'master' into errorbars-mplot3d
vlas-sokolov Jun 10, 2020
0d8c3e3
port most of the changes done in #15037 for 2d errorbars
Jun 18, 2020
93c9de5
Apply suggestions from code review
vlas-sokolov Jul 26, 2020
1c73204
fix more pr comments
Jul 29, 2020
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
Prev Previous commit
Next Next commit
rebase against current master + fix dropped deprecations
  • Loading branch information
Vlas Sokolov committed Apr 16, 2020
commit c30c276a7a95fe83045410a4e434fd3d3c93f900
47 changes: 25 additions & 22 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from collections import defaultdict
from functools import reduce
imp 8000 ort logging
import math
import textwrap

Expand All @@ -25,16 +26,16 @@
import matplotlib.docstring as docstring
import matplotlib.scale as mscale
from matplotlib.axes import Axes, rcParams
from matplotlib.axes._base import _axis_method_wrapper
from matplotlib.axes._base import _axis_method_wrapper, _process_plot_format
from matplotlib.transforms import Bbox
from matplotlib.tri.triangulation import Triangulation
from matplotlib.colors import Normalize, LightSource
from matplotlib.axes._base import _process_plot_format

from . import art3d
from . import proj3d
from . import axis3d

_log = logging.getLogger(__name__)


@cbook.deprecated("3.2", alternative="Bbox.unit()")
def unit_bbox():
Expand Down Expand Up @@ -2846,19 +2847,19 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
"""
had_data = self.has_data()

if not cbook.iterable(x):
if not np.iterable(x):
x = [x]
if not cbook.iterable(y):
if not np.iterable(y):
y = [y]
if not cbook.iterable(z):
if not np.iterable(z):
z = [z]

if fmt is None:
fmt = 'none'
msg = ('Use of None object as fmt keyword argument to ' +
'suppress plotting of data values is deprecated ' +
'since 1.4; use the string "none" instead.')
warnings.warn(msg)
_log.warning(msg)

plot_line = (fmt.lower() != 'none')
label = kwargs.pop("label", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this, can you add *, label=None to the signature? Or is there a deliberate reason to not list this in the argument list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably the reason is that 2d ax.errorbar was written for Python2, where that signature would throw a SyntaxError. I made this PR taking the following comment from #568 - "just mirror ax.errorbar as closely as possible" as a guideline (reviewing its source side-by-side might be easier to show what bits are actually new in this PR). Should I still change it?

Expand All @@ -2873,7 +2874,7 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
if 'color' in kwargs:
base_style['color'] = kwargs.pop('color')
else:
base_style = six.next(self._get_lines.prop_cycler)
base_style = next(self._get_lines.prop_cycler)

base_style.update(fmt_style_kwargs)
if 'color' not in base_style:
Expand Down Expand Up @@ -2936,10 +2937,10 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
self.add_line(data_line)

def _bool_asarray_helper(d, expected):
if not cbook.iterable(d):
if not np.iterable(d):
return np.asarray([d] * expected, bool)
else:
return np.asarray(d, bool)

return np.asarray(d, bool)

def _mask_lists(xs, ys, zs, mask=None):
""" Applies a mask to three lists. """
Expand All @@ -2958,14 +2959,14 @@ def _unpack_errs(data, err, lomask, himask):
# List of endpoint coordinates, used for auto-scaling
coorderrs = []

for data, err, i_xyz, lolims, uplims in zip([x, y, z],
[xerr, yerr, zerr], range(3),
[xlolims, ylolims, zlolims],
[xuplims, yuplims, zuplims]):
for data, err, i_xyz, lolims, uplims in zip(
[x, y, z], [xerr, yerr, zerr], range(3),
[xlolims, ylolims, zlolims], [xuplims, yuplims, zuplims]):

if err is None:
continue

if not cbook.iterable(err):
if not np.iterable(err):
err = [err] * len(data)
lolims = _bool_asarray_helper(lolims, len(x))
uplims = _bool_asarray_helper(uplims, len(x))
Expand All @@ -2976,17 +2977,18 @@ def _unpack_errs(data, err, lomask, himask):
# as long as the actual data plotted stays as lists.
# This is due to unit preservation issues
# (c.f. the 2d errorbar case).
rolling_mask = np.roll([1.,0.,0.], i_xyz)
rolling_mask = np.roll([1., 0., 0.], i_xyz)
# TODO: why is this here?
if err is not None:
err = np.atleast_1d(err)

# a nested list structure that expands to (xl,xh),(yl,yh),(zl,zh),
# where x/y/z and l/h correspond to dimensions and low/high
# positions of errorbars in a dimension we're looping over
coorderr = [_unpack_errs(coord, err*rolling_mask[i],
~lolims & everymask, ~uplims & everymask)
for i, coord in enumerate([x, y, z])]
coorderr = [
_unpack_errs(coord, err * rolling_mask[i],
~lolims & everymask, ~uplims & everymask)
for i, coord in enumerate([x, y, z])]
(xl, xh), (yl, yh), (zl, zh) = coorderr

# define the markers used for errorbar caps and limits below
Expand Down Expand Up @@ -3026,8 +3028,9 @@ def _unpack_errs(data, err, lomask, himask):
# example, 180 deg rotation around z-axis would flip
# the markers around... However, this solution is
# spiritually close to that of 2d errorbar function
limits = [_unpack_errs(coord, err*rolling_mask[i], uplims,
lolims) for i, coord in enumerate([x, y, z])]
limits = [
_unpack_errs(coord, err*rolling_mask[i], uplims, lolims)
for i, coord in enumerate([x, y, z])]
(xlo, xup), (ylo, yup), (zlo, zup) = limits

lolims_xyz = _mask_lists(xup, yup, zup, lolims & everymask)
Expand Down
0