MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_errorbar

Function test_errorbar

lib/matplotlib/tests/test_axes.py:4509–4560  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4507@image_comparison(['errorbar_basic.png', 'errorbar_mixed.png', 'errorbar_basic.png'],
4508 style='mpl20')
4509def test_errorbar():
4510 # longdouble due to floating point rounding issues with certain
4511 # computer chipsets
4512 x = np.arange(0.1, 4, 0.5, dtype=np.longdouble)
4513 y = np.exp(-x)
4514
4515 yerr = 0.1 + 0.2*np.sqrt(x)
4516 xerr = 0.1 + yerr
4517
4518 # First illustrate basic pyplot interface, using defaults where possible.
4519 fig = plt.figure()
4520 ax = fig.gca()
4521 ax.errorbar(x, y, xerr=0.2, yerr=0.4)
4522 ax.set_title("Simplest errorbars, 0.2 in x, 0.4 in y")
4523
4524 # Now switch to a more OO interface to exercise more features.
4525 fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
4526 ax = axs[0, 0]
4527 ax.errorbar(x, y, yerr=yerr, fmt='o')
4528 ax.set_title('Vert. symmetric')
4529
4530 # With 4 subplots, reduce the number of axis ticks to avoid crowding.
4531 ax.locator_params(nbins=4)
4532
4533 ax = axs[0, 1]
4534 ax.errorbar(x, y, xerr=xerr, fmt='o', alpha=0.4)
4535 ax.set_title('Hor. symmetric w/ alpha')
4536
4537 ax = axs[1, 0]
4538 ax.errorbar(x, y, yerr=[yerr, 2*yerr], xerr=[xerr, 2*xerr], fmt='--o')
4539 ax.set_title('H, V asymmetric')
4540
4541 ax = axs[1, 1]
4542 ax.set_yscale('log')
4543 # Here we have to be careful to keep all y values positive:
4544 ylower = np.maximum(1e-2, y - yerr)
4545 yerr_lower = y - ylower
4546
4547 ax.errorbar(x, y, yerr=[yerr_lower, 2*yerr], xerr=xerr,
4548 fmt='o', ecolor='g', capthick=2)
4549 ax.set_title('Mixed sym., log y')
4550 # Force limits due to floating point slop potentially expanding the range
4551 ax.set_ylim(1e-2, 1e1)
4552
4553 fig.suptitle('Variable errorbars')
4554
4555 # Reuse the first testcase from above for a labeled data test
4556 data = {"x": x, "y": y}
4557 fig = plt.figure()
4558 ax = fig.gca()
4559 ax.errorbar("x", "y", xerr=0.2, yerr=0.4, data=data)
4560 ax.set_title("Simplest errorbars, 0.2 in x, 0.4 in y")
4561
4562
4563@image_comparison(['mixed_errorbar_polar_caps.png'], remove_text=True,

Callers

nothing calls this directly

Calls 10

sqrtMethod · 0.80
figureMethod · 0.80
gcaMethod · 0.80
locator_paramsMethod · 0.80
suptitleMethod · 0.80
errorbarMethod · 0.45
set_titleMethod · 0.45
subplotsMethod · 0.45
set_yscaleMethod · 0.45
set_ylimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…