5

I'm using gnuplot to generate some plots with an x axis ranging from 0 to 20. Is it possible to set the color of some tics or axis numbers to a different color from the standard black?

I only found a way to change the color of the all the numbers in the x axis red with set xtics textcolor rgb "red".

What I need is to be able to change the color of the tic or number at x=0,3,6,... to red and all the others should stay black. Is this possible with gnuplot?

8
  • Are you interested in a particular terminal type? It seems that one should be able to do this at least for those terminals where the color can be specified as part of the label text. I don't think gnuplot's enhanced text mode lets you change the color, but any of the latex-based terminals probably would. Commented Apr 3, 2018 at 18:35
  • I am interested in changing the color of the tic, not of the label text. I use the postscript terminal. Commented Apr 3, 2018 at 19:23
  • Thanks. Just to clarify: you want to change the color of the tic (the short vertical line that crosses the x axis), and not the color of the tic label (the numbers 0, 3, 7, ... mentioned in the original posting)? Commented Apr 3, 2018 at 21:06
  • More precisely: I'd like to change the color of some (not all) of the x tics, and yes, not of the label text, @user8153 Commented Apr 4, 2018 at 7:11
  • 1
    @derwodamaso Are there any problems with the logarithmic axis? If, for example, you want a red tic at x=1.5, you could do set arrow from first 1.5, graph 0 to first 1.5, graph 0.01 nohead linecolor "red". Commented Apr 6, 2018 at 20:17

2 Answers 2

4
+50

The color of the tic marks is set by the border color, so one can do something like this:

reset
set multiplot

set xrange [-5:5]

set xtics -5,1,0                  # these tic marks will show up in black (the  default border color)
set yrange [] writeback           # save auto-generated y range for later
plot sin(x)

set border 0 linecolor "red"      # change border color, and turn off drawing of the border
set xtics 1,1,5 textcolor "blue"  # these tic marks will show up in the new border color, and we can specify the color of the labels
unset ytics                       # we  don't want to display the y tics again
set yrange restore                # use same range for  y axis as before

unset key
plot NaN

unset multiplot

enter image description here

This solution also uses multiplot, but uses the second plot only to draw tic marks and labels whose color is different from the default black. It is important that the two plots have the same ranges and margins.

Sign up to request clarification or add additional context in comments.

1 Comment

I thought I had tried that, but the two plots' borders were not aligned. Probably messed up template file... But this here clearly works. Thanks!
0

This might be cheating a bit, just create the plot twice with different xtics command on top of each other:

set xrange [0:10]

set multiplot
set size 1,1
set origin 0,0
set xtics 1 textcolor rgbcolor "green"
plot sin(x)

set size 1,1
set origin 0,0
set xtics 1, 2 textcolor rgbcolor "red"
plot sin(x)

unset multiplot

seems to work for me (gnuplot: Version 5.2 patchlevel 2 last modified 2017-11-15)

1 Comment

Works for the labels, but not for the tics. For my purpose, only some particular tics should have different color than the other tics. But nice idea with the multiplot! I tried it, together with stackoverflow.com/questions/12408459/gnuplot-colored-tic-marks but then the tics of the different plots are not aligned because somehow the borders are different.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.