# Contour linestyle in Cairomakie

**URL:** https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602
**Category:** New to Julia
**Tags:** plotting
**Created:** [June 20, 2023, 11:29am UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602 "2023-06-20T11:29:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Subhajit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/subhajit/32/49092_2.png) [@Subhajit](https://discourse.julialang.org/u/Subhajit)
#### Post date: [June 20, 2023, 11:29am UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602/1 "2023-06-20T11:29:31Z")

</div>

Hi!  
I’m new to Julia. I’m trying to do simple contour plot using Cairomakie.  
I’m not able to change the linestyle of the plot, i.e., “positive” value is for solid line and “negative” value is dotted line (it’s default in python matplotlib).  
Is there a way to do it in Cairomakie?

Thanks  
Subhajit

---

<div class="post-metadata">

### Author: ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)
#### Post date: [June 21, 2023, 5:12am UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602/2 "2023-06-21T05:12:55Z")

</div>

The `linestyle` argument is the same as for the [Page Redirection](https://docs.makie.org/stable/examples/plotting_functions/lines/#linestyles) .  
E.g.:

```julia
xs = LinRange(0, 10, 100);
ys = LinRange(0, 15, 100);
zs = [cos(x) * sin(y) for x in xs, y in ys];
contour(xs, ys, zs, linestyle=:dashdot, linewidth=2)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b03bc3ddd053f38bc0cb85ede3bd6d634eb22025.png)

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 21, 2023, 5:45am UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602/3 "2023-06-21T05:45:07Z")

</div>

One `contour` call is currently drawn with a single `lines` invocation to be more performant, but `lines` does not allow for multiple linestyles to be passed (which sort of makes sense because you cannot interpolate between two different linestyles between two adjacent points).

So the workaround is to call `contour` multiple times, either once per level, or just once per linestyle. You can pass the desired levels manually:

```julia
xs = LinRange(0, 10, 100)
ys = LinRange(0, 15, 100)
zs = [cos(x) * sin(y) for x in xs, y in ys]
f, ax, c = contour(xs, ys, zs, levels = [-0.2, -0.4, -0.6, -0.8], linestyle=:dashdot, colormap = :Blues)
contour!(ax, xs, ys, zs, levels = [0, 0.2, 0.4, 0.6, 0.8], colormap = :Reds)
f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b03f345ed73031f6f381d07879fc87cb04b21b9.png)

---

<div class="post-metadata">

### Author: ![Subhajit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/subhajit/32/49092_2.png) [@Subhajit](https://discourse.julialang.org/u/Subhajit)
#### Post date: [June 21, 2023, 4:26pm UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602/4 "2023-06-21T16:26:30Z")

</div>

Thanks a lot.

---

<div class="post-metadata">

### Author: ![Subhajit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/subhajit/32/49092_2.png) [@Subhajit](https://discourse.julialang.org/u/Subhajit)
#### Post date: [June 21, 2023, 4:27pm UTC](https://discourse.julialang.org/t/contour-linestyle-in-cairomakie/100602/5 "2023-06-21T16:27:09Z")

</div>

Now it works. Thank you.
