0

Matplotlib's ax.fill_between plotting function has the cmap parameter and I was trying to use it to fill the area under the curve with a gradient. However, setting cmap in this function doesn't seem to be doing anything or I'm missing something?

This is what I've tried:

import matplotlib.pyplot as plt

x = [0, 1, 2, 3, 4, 5]
y = [2, 4, 1, 3, 0.5, 2]

fig, ax = plt.subplots(
    figsize=(10,6),
    facecolor="white"
)

ax.fill_between(
    x=x,
    y1=y,
    cmap="cool"
)

and another version of it:

ax.fill_between(
    x=x,
    y1=y,
    cmap=plt.get_cmap("cool")
)

I would also try to apply cmap to color or facecolor property but it would throw an error.

So all I always end up with is this:

enter image description here

mozway
  • 194,879
  • 13
  • 39
  • 75
pawjast
  • 21
  • 5
  • Does this answer your question? [Is it possible to get color gradients under curve in matplotlib?](https://stackoverflow.com/questions/29321835/is-it-possible-to-get-color-gradients-under-curve-in-matplotlib) – mozway May 17 '23 at 11:51
  • Not really. I know there are work arounds like the one you've posted where you create image with a gradient and use the shape of the curve to clip it. My question is: **WHY** is there a `cmap` parameter in `fill_between` function if it does nothing? Or if it works as with any other plotting function - how to properly use it? – pawjast May 17 '23 at 12:08

0 Answers0