How to rotate x-axis labels on Gnuplot

Question: I want to rotate the x-axis (xtics) labels in a Gnuplot figure. What is the Gnuplot command to rotate x-axis labels?

To rotate x-axis labels on Gnuplot, you can use the following command.

set xtics rotate {by <angle>} {offset <x,y>}

It will rotate x-axis labels by <angle> degrees counter-clockwise. Optionally, you can also specify the offset of the labels to adjust their positions. Without any angle parameter, it will by default rotate the labels by 90 degrees.

For example, the following Gnuplot script will produce a bar graph with x-axis labels rotated by 90 degrees.

set terminal png font "Helvetica" 16
set output 'plot.png'
set key left
set grid y
set boxwidth 0.5
set style fill solid 1.0 border -1
set ytics 10 nomirror
set yrange [:]
set ylabel "Number of Customers"
set xtics rotate
set bmargin 8
plot 'plot1.dat' using 1:3:xtic(2) notitle with boxes

The next Gnuplot script will create a bar graph with x-axis labels rotated by 45 degrees, and their positions adjusted.

set terminal png font "Helvetica" 16
set output 'plot.png'
set key left
set grid y
set boxwidth 0.5
set style fill solid 1.0 border -1
set ytics 10 nomirror
set yrange [:]
set ylabel "Number of Customers"
set xtics rotate by 45 offset -0.8,-1.8
set bmargin 3
plot 'plot2.dat' using 1:3:xtic(2) notitle with boxes

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *