# Synchronizing Colors for Functions and Derivatives in Julia Plots using RecipesBase.jl

**URL:** <https://discourse.julialang.org/t/synchronizing-colors-for-functions-and-derivatives-in-julia-plots-using-recipesbase-jl/103939>\
**Category:** General Usage\
**Tags:** plotting, plots, recipe\
**Created:** [September 17, 2023, 1:44am UTC](https://discourse.julialang.org/t/synchronizing-colors-for-functions-and-derivatives-in-julia-plots-using-recipesbase-jl/103939 "2023-09-17T01:44:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [September 17, 2023, 1:44am UTC](https://discourse.julialang.org/t/synchronizing-colors-for-functions-and-derivatives-in-julia-plots-using-recipesbase-jl/103939/1 "2023-09-17T01:44:11Z")

</div>

I’m working with Julia and the `Plots.jl` package to create subplots of functions and their derivatives, and I want to synchronize the colors between corresponding functions and their derivatives using `RecipesBase.jl` . Here’s what I have so far:

```julia
using Plots

# Define your x-values and functions
x = 0:0.1:2π
y1 = sin.(x)
y2 = cos.(x)
y3 = tan.(x)
y4 = cot.(x)

# Calculate derivatives
dy1 = cos.(x)
dy2 = -sin.(x)
dy3 = sec.(x).^2
dy4 = -csc.(x).^2

# Define a custom color palette
my_palette = palette(:default, color=:auto, marker=:auto)

# Create the first group of subplots with synchronized colors
p1 = plot(x, y1, label="sin(x)", color=my_palette[1])
plot!(x, y2, label="cos(x)", color=my_palette[2])
plot!(x, y3, label="tan(x)", color=my_palette[3])
plot!(x, y4, label="cot(x)", color=my_palette[4])

# Create the second group of subplots with synchronized colors
p2 = plot(x, dy1, label="sin'(x)", color=my_palette[1], linestyle=:dash)
plot!(x, dy2, label="cos'(x)", color=my_palette[2], linestyle=:dash)
plot!(x, dy3, label="tan'(x)", color=my_palette[3], linestyle=:dash)
plot!(x, dy4, label="cot'(x)", color=my_palette[4], linestyle=:dash)

# Combine the subplots side by side
plot(p1, p2, layout=(1, 2), legend=true)

```

I want to achieve the same result using `RecipesBase.jl` to define a custom recipe for color synchronization. How can I implement this using `RecipesBase.jl` ?
