# Makie.jl - How to plot a colorlegend?

**URL:** https://discourse.julialang.org/t/makie-jl-how-to-plot-a-colorlegend/46132
**Category:** General Usage
**Tags:** question, plotting, makie
**Created:** [September 6, 2020, 7:08am UTC](https://discourse.julialang.org/t/makie-jl-how-to-plot-a-colorlegend/46132 "2020-09-06T07:08:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)
#### Post date: [September 6, 2020, 7:08am UTC](https://discourse.julialang.org/t/makie-jl-how-to-plot-a-colorlegend/46132/1 "2020-09-06T07:08:42Z")

</div>

I’m trying to plot a colorlegend when its colorrang is (::Float64,::Float64).  
But this sample code doesn’t work.

```julia
using Makie
using FileIO
using LinearAlgebra
using AbstractPlotting

r = LinRange(-20, 20, 500); # our value range

ρ(x, y, z) = exp(-((x)^2 + (y)^2 + (z)^2)) # function (charge density)

# create a Scene with the attribute `backgroundcolor = :white`,
# can be any compatible color. Useful for better contrast and not killing your eyes with a white background.
scene = Scene(backgroundcolor = :white)

volume!(
    scene,
    r, r, r, # coordinates to plot on
    ρ, # charge density (functions as colorant)
    algorithm = :mip, # maximum-intensity-projection
    colorrange = (0,0.5),
      colormap = :blues,
    transparency = true
)

update_cam!(scene, Vec3f0(1,1.5,1.0), Vec3f0(0))
scene[Axis].names.textcolor = :gray # let axis labels be seen on dark background

cm = colorlegend(
    scene[end], # access the plot of scene 
    raw = true, # without axes or grid
    camera = campixel!, # gives a concrete bounding box in pixels
                                         # so that the `vbox` gives you the right size
    width = ( # make the colorlegend longer so it looks nicer
        30, # the width
        540 # the height
    )
    )

scene_final = vbox(scene, cm) # put the colorlegend and the plot together in a `vbox`

save("test.png",scene_final)

```

```julia
MethodError: no method matching optimize_ticks(::Int64, ::Float64; k_min=4, k_max=8)
Closest candidates are:
  optimize_ticks(::T, !Matched::T; extend_ticks, Q, k_min, k_max, k_ideal, granularity_weight, simplicity_weight, coverage_weight, niceness_weight, strict_span, span_buffer) where T at /Users/username/.julia/packages/PlotUtils/10ojB/src/ticks.jl:136

```

If colorrange = (0,0.5) → colorrange = (0,1.0), the code passes.  
Is there a method to display a colorlegend with colorrange = (0,0.5)?

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [December 8, 2020, 9:37am UTC](https://discourse.julialang.org/t/makie-jl-how-to-plot-a-colorlegend/46132/2 "2020-12-08T09:37:47Z")

</div>

Could it be that the working code was `colorrange = (0.0, 1.0)` rather than `colorrange = (0, 1.0)`?

I think Makie is just being picky with the types: using `colorrange = (0.0, 0.5)` works for me.
