Skip to content

Plotting an error band along a curve #17398

Closed
@Waljakov

Description

@Waljakov

Bug report

Bug summary

pyplot.fill_between(x, y1, y2) does not fill areas, where curves y1 and y2 are crossing.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

def lissajous(t):
    """Calculate Lissajous Curve"""
    x = np.cos(t)
    y = np.sin(2 * t)
    return x, y

data = np.arange(0, 2 * np.pi, 0.01)

plt.plot(*lissajous(data))
plt.fill_between(
    lissajous(data)[0], lissajous(data)[1] - 0.5, lissajous(data)[1] + 0.5, alpha=0.25
)

plt.show()

Actual outcome

Lissajous_issue

Expected outcome

Lissajous_expected

Note
I came across this problem while trying to use fill_between() as 'errorbars' for parametric functions. If this is not the intended use, I would be glad if someone has suggestions for a workaround.
Keep up the good work!

Matplotlib version

  • Operating system: Arch Linux x86_64, Kernel 5.6.11-arch1-1
  • Matplotlib version: 3.1.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.7
  • Jupyter version (if applicable):
  • Other libraries: numpy: 1.18.1

matplotlib installed via anaconda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions