How to set the same color of gradient in joyploy plot fill?

21 Views Asked by At

target results

As shown in the picture above, I want to reproduce a similar effect in the picture. The fill color of each plot is the same colormap that gradients from blue to red.

Attached is my code and data

data:here

However, when I pass in a colormap, all the effects are as follows.

The fill of each line is not the same

How can I modify it to achieve the desired result?

Current results


import xarray as xr
import numpy as np
import pandas as pd
import joypy
import matplotlib as mpl   
import cmaps
from matplotlib.colors import ListedColormap 


da = xr.open_dataset(r'J:\code\sst.mnmean.nc').sortby('lat').sel(time=slice('1982', '2021'))


sst_1991_2020 = da.sel(time=slice('1991', '2020')).sst.mean(['time'])
sst_difference = (da.sst-sst_1991_2020).mean(['lon','lat'])

df = sst_difference.to_dataframe().reset_index()



df['time'] = pd.to_datetime(df['time'])
df['year'] = df['time'].dt.year
labels = df['year']

years = np.arange(df['time'].dt.year.min(), df['time'].dt.year.max() + 1, 5)




norm =  mpl.colors.Normalize(vmin=-1, vmax=1)   
                                         
cmap =   cmaps.BlueWhiteOrangeRed 
                                       
newcolors=cmap(np.linspace(0,1,12))
                               
newcmap=ListedColormap(newcolors[::1])  


fig,ax = joypy.joyplot(df, 
              by="year", 
              column="sst", 
              range_style='all', 
              linecolor = "white",
              grid="y",
              # ylim='owd',
              # fill=False,
              linewidth=1,
              # sharey=True,
              tails = 0.2, 
              legend=True, 
              # fade=True, 
              overlap=2.5,
              x_range=(-1.5,1.5),
              background='w' ,
              figsize=(6, 10),
              alpha=0.6,
            colormap=newcmap,
            
            title="Global monthly sst  1981-2020 \n(°C above 1991-2020 average)",
            kind="kde", 
            bins=20)
0

There are 0 best solutions below