 # How to draw only specific contour on a contourf plot?

Hi! So I have the code below:

``````
import xarray as xr
import hvplot.xarray
import holoviews as hv

np.random.seed(1)
refdist = np.array(range(100,700,100))
depth = np.array(range(5,30,5))
data = np.random.uniform(low = -5, high = 5, size = (len(refdist), len(depth)))

ds = xr.Dataset(
{   "V": (["refdist", "depth"], data),
},
coords={
"refdist": (refdist),
"depth": (depth),
},
)

plot=ds['V'].hvplot.contourf(z='V', x='refdist', y='depth', levels=10)
plot
``````

And I would like to draw only a specific contour (here the 0-contour). I have two questions:

1. Is there an easy way to do that without having to overlay a new contour object?
2. In the figure above, how can I change the linestyle options of the lines separating the filled contourf? (for example: changing the linestyle , the color, the width?) I could not find how to do that for contourf object.

I think I found a beginning of an answer here: https://stackoverflow.com/a/54681316/13890678

EDIT 08/01/2021 - This link is about the `holoviews.Contours` function rather than `hvplot.contour`

What if you do
levels = [0, 0]
or
levels[-0.0001, 0.0001]

1 Like

I realised my previous replied was more a holoview solution. For hvplot, I managed to find this solution:

``````
import xarray as xr
import hvplot.xarray
import holoviews as hv

np.random.seed(1)
refdist = np.array(range(100,700,100))
depth = np.array(range(5,30,5))
data = np.random.uniform(low = -5, high = 5, size = (len(refdist), len(depth)))

ds = xr.Dataset(
{   "V": (["refdist", "depth"], data),
},
coords={
"refdist": (refdist),
"depth": (depth),
},
)

contf=ds['V'].hvplot.contourf(z='V', x='refdist', y='depth', levels=10)

cont1=ds['V'].hvplot.contour(z='V', x='refdist', y='depth', levels=10,cmap=['#000000'])
cont1.opts(line_dash='dotdash',line_width=0.5)

cont2=ds['V'].hvplot.contour(z='V', x='refdist', y='depth', levels=,cmap=['#000000'])

overlay_obj = contf * cont1 * cont2
overlay_obj
``````

I am still learning holoviz so don’t hesitate to let me know if there is a better way!

1 Like