2

This is my attempt at making the xtics label color match the line color in a box plot in gnuplot:

$DATA << EOD
1 1
2 2
3 3
EOD

set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"

set key off

set boxwidth 0.5
set style fill solid 0.5

set xrange [0:4]
set yrange [0:4]

set xtics     ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"

plot $DATA using 1:2:1 with boxes linecolor variable

But it does not work: enter image description here

Any idea? Thanks!

1 Answer 1

1

I'm not sure whether you can set xtics individually in different colors. So, the following solution sets the xtics as empty lines and you plot your xtics with labels with a certain offset. The disadvantage is that you have to set the y-position here: (0) with offset 0,-1. I hope there are better solutions.

Code:

### "xtic labels" in different colors
reset session

$Data << EOD
1 1
2 2
3 3
EOD

set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"

set key off
set boxwidth 0.5
set style fill solid 0.5

set xrange [0:4]
set yrange [0:4]
set format x "\n"     # xtic label empty line

plot $Data u 1:2:1 w boxes lc var, \
        '' u 1:(0):1:1 w labels tc var offset 0,-1 
### end of code

Alternatively, you could use an offset relative to the graph:

plot $Data u 1:2:1 w boxes lc var, \
        '' u 1:(0):1:1 w labels tc var offset 0, graph -0.05 

Result:

enter image description here

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

Comments

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.