Black Lives Matter. Please consider donating to Black Girls Code today.

Gradient Lines in Dash


I’m trying to create a line chart with the line’s color being gradient (e.g. blue slowly fading to green in color) within Dash. After doing some research (Scatter line gradient?) it seems that it’s a feature that has been “worked” on for a few years, but never completed.

I was wondering if it’s possible to do this maybe in other ways? Throwing ideas out here, but could cmocean be used? It seems as though they have a gradient feature: – to my understanding Plotly can integrate with cmocean (

However, I’m not sure how to create a cmocean graph within Dash.

I tried implementing the following code into my Dash app but it did not work:

import cmocean
import as cmo
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 3))
ax = fig.add_subplot(1, 2, 1)
Z = np.random.randn(10,10)
ax.pcolormesh(Z, cmap=cmo.matter)

ax = fig.add_subplot(1, 2, 2)
lightcmap =, 0.5)
ax.pcolormesh(Z, cmap=lightcmap)

My original attempt was: ‘line’: {‘color’: ‘linear-gradient(90deg, red, red 60%, white)’ }

            'data': [
                 { "x": MORTGAGE30US['date'],"y": MORTGAGE30US['value'],"mode": "lines","name": '30 YR', 'line': {'color': 'linear-gradient(90deg, red, red 60%, white)' }},
                 { "x": MORTGAGE15US['date'],"y": MORTGAGE15US['value'],"mode": "lines","name": '15 YR',},

            'layout': {
                'title': 'MORTGAGE RATES',
                "paper_bgcolor": "rgb(46, 54, 65)",
                "plot_bgcolor": "rgb(46, 54, 65)",
                'font': {
                    'color': "rgb(255,255,255)"