Simple question, but I did not find the answer anywhere:

Is it possible to add a color gradient to the ticks in a plot?

For example, imagine to have a density plot where some areas are very dark and some very bright. I would like to display whiter ticks in the darker regions and blacker ticks in the brighter regions.

Thank you!

  • $\begingroup$ Why would you need that? Ticks can be on the frame outside of the plot. $\endgroup$ Commented Dec 14, 2023 at 15:56
  • $\begingroup$ Because... why not? I mean, I know I can put them outside, but I'd say it's a legitimate question to ask if anybody has an idea on how to implement what I asked. $\endgroup$
    – Lele
    Commented Dec 14, 2023 at 16:28
  • $\begingroup$ closely related Q/A: Makes AxesStyles multiple colors $\endgroup$
    – kglr
    Commented Dec 14, 2023 at 21:03

1 Answer 1


Sure you can, but you will have to roll your own tick generator:

gradientTicks[tickList_] := gradientTicks[tickList, Scaled[0.02], {White, Black}]
gradientTicks[tickList_, length_] := gradientTicks[tickList, length, {White, Black}]
gradientTicks[tickList_, length_, {lightColor_, darkColor_}] :=
 {#, #, length,
     Blend[{lightColor, darkColor}, Rescale[#, MinMax[tickList]]]
 } & /@ tickList

  x^2 + y^2, {x, y} \[Element] Rectangle[{0, 0}, {2, 2}],
  Frame -> False, Axes -> True,
  Ticks -> {
    gradientTicks[Range[0, 2, 0.25], Scaled[0.1], {Yellow, Darker@Blue}], 

enter image description here

  • $\begingroup$ Nice solution, thank you! $\endgroup$
    – Lele
    Commented Dec 14, 2023 at 18:07
  • $\begingroup$ @Lele I'm glad you liked it! Thank you for the accept as well. $\endgroup$
    – MarcoB
    Commented Dec 14, 2023 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.