# How to change colormap for plotting with arrows()?

**URL:** https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323
**Category:** New to Julia
**Tags:** makie
**Created:** [January 26, 2024, 11:05pm UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323 "2024-01-26T23:05:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)
#### Post date: [January 26, 2024, 11:05pm UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323/1 "2024-01-26T23:05:55Z")

</div>

Julia has an awesome documentation, including an example for [arrows()](https://docs.makie.org/stable/reference/plots/arrows/). However I don’t figure, how to change the colormap that shows the strength of the arrows. I’d like to change it to :bluesreds. If you know how, let me know. 😃

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [January 27, 2024, 2:33am UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323/2 "2024-01-27T02:33:23Z")

</div>

There is a `colormap` attribute. The available colormaps are listed here:  
[https://docs.makie.org/stable/explanations/colors/#colormaps](https://docs.makie.org/stable/explanations/colors/#colormaps)

I modified the script slightly to set the keyword attribute `colormap = :bluesreds` as below.

```julia
using GLMakie

f = Figure(size = (800, 800))
Axis(f[1, 1], backgroundcolor = "black")

xs = LinRange(0, 2pi, 20)
ys = LinRange(0, 3pi, 20)
us = [sin(x) * cos(y) for x in xs, y in ys]
vs = [-cos(x) * sin(y) for x in xs, y in ys]
strength = vec(sqrt.(us .^ 2 .+ vs .^ 2))

arrows!(xs, ys, us, vs, arrowsize = 10, lengthscale = 0.3,
    arrowcolor = strength, linecolor = strength, colormap = :bluesreds)

f

```

I got the following result.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/f/cff96087753f30d01bc162db7ea737db2b036b4b.png)

---

<div class="post-metadata">

### Author: ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)
#### Post date: [January 27, 2024, 11:06am UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323/3 "2024-01-27T11:06:47Z")

</div>

> [@mkitti](#):
>
> `colormap = :bluesreds`

Great, thank you! I have also tried that, but Visual Studio didn’t show me a picture (only if I remove the colormap attribute). Seems it was a bug. Now where I restarted it all works fine.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [January 27, 2024, 11:09am UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323/4 "2024-01-27T11:09:52Z")

</div>

Note that within a REPL session, the last `f` is very critical. This implicitly invokes the equivalent of `display(f)`, which causes the figure to show up.

---

<div class="post-metadata">

### Author: ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)
#### Post date: [January 27, 2024, 12:49pm UTC](https://discourse.julialang.org/t/how-to-change-colormap-for-plotting-with-arrows/109323/5 "2024-01-27T12:49:33Z")

</div>

For this reason I typically wrap my plotting functions in a `begin end` block that always ends with `fig` so no matter what I change the figure always comes out 🙂
