Gnuplot - color some ticks or axis numbers in different colors

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

I just found a way to change the color of all numbers on the x axis to red using set xtics textcolor rgb "red"

.

I need to change the color of the tic or number x=0,3,6,...

to red, while everyone else should stay black. Is this possible with gnuplot?

+3


source to share


2 answers


The color of the tic marks is set by the border color, so you 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 a multiplier, but uses the second chart only to draw tick marks and ticks that are different from black by default. It is important that both graphs have the same ranges and margins.

+1


source


This can be changed a bit, just create the graph twice with another 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)

0


source







All Articles