4
votes

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?

2
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. - user8153
I am interested in changing the color of the tic, not of the label text. I use the postscript terminal. - rehctawrats
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)? - user8153
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 - rehctawrats
@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". - user8153

2 Answers

3
votes

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.

0
votes

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)