# Makie recipe for creating a scatter plot with points colored by value

**URL:** <https://discourse.julialang.org/t/makie-recipe-for-creating-a-scatter-plot-with-points-colored-by-value/91754>\
**Category:** Visualization\
**Created:** [December 16, 2022, 7:56pm UTC](https://discourse.julialang.org/t/makie-recipe-for-creating-a-scatter-plot-with-points-colored-by-value/91754 "2022-12-16T19:56:25Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [December 19, 2022, 5:52pm UTC](https://discourse.julialang.org/t/makie-recipe-for-creating-a-scatter-plot-with-points-colored-by-value/91754/5 "2022-12-19T17:52:52Z")

</div>

This is much easier than I had thought, for anyone that comes next here is the recipe (See Makie docs has a more [generic scatter example](https://docs.makie.org/stable/examples/plotting_functions/scatter/#using_points) and examples for [colored lines](https://beautiful.makie.org/dev/examples/generated/2d/lines/line_cmaps/):

```julia
   using CairoMakie

    # create synthetic data
    n = 1000;
    x = 1:n;
    y = sin.(collect(x) .* .05);
    z = vcat(1:n/2, n/2:-1:1) .- n/4

    # set color axis limits which by default is automatically equal to the extrema of the color values
    colorrange = [-n/4, n/4];
    
    # choose color map [https://docs.juliahub.com/AbstractPlotting/6fydZ/0.12.10/generated/colors.html]
    cmap = :balance
    
    # make colored scatter plot
    fig = Figure()
    scatter(fig[1, 1], x, y; color=z, colormap = cmap, markersize=10, strokewidth=0, colorrange = colorrange)

    # add colorbar 
    Colorbar(fig[1, 2], colorrange = colorrange, colormap = cmap,
    label = "colored data")

    # show Figure
    fig

```

 ![example_scatter_colored](https://global.discourse-cdn.com/julialang/original/3X/a/3/a3b16a9c4f19274ce5b52fe33e26138ed7371741.jpeg)

---

_[View the full topic](https://discourse.julialang.org/t/makie-recipe-for-creating-a-scatter-plot-with-points-colored-by-value/91754)._
