0

I want to get a plot a colormap with discrete intervals, each interval associated to a color. My dataset is in xarray and works well. I tried the code below but I get the following error. I tried with norm.vmax=100 and without. Any help is welcome.

ValueError: Passing a Normalize instance simultaneously with vmin/vmax is not supported. Please pass vmin/vmax directly to the norm when creating it.

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 7))
cmap = mpl.colors.ListedColormap(['blue', 'yellow', 'red'])
bounds = np.array([0, 1, 5,100]) norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
norm.vmax=100 norm.vmin=0
ds_p.plot(cmap=cmap, norm=norma, cbar_kwargs={'pad' :0.1, 'shrink': 0.5, 'label': '[% of year]'}) plt.show()
Robert
9,08661 gold badges194 silver badges215 bronze badges
asked May 25, 2023 at 22:24

1 Answer 1

0

You should try passing the levels argument to your plot method.

See here for details.

answered Oct 27, 2023 at 19:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.