Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot xticlabels with several lines

Tags:

plot

gnuplot

if I add a xticlabel that uses 3 lines gnuplot cuts at the middle of the second line. Is there any method to have xticlabels with several lines?

This is my data file:

"[17h30,19h00] 25" 1
"[03h30,10h00] 21" 1
"[03h00,12h00] 26" 2
"[18h00,19h30] 27" 3
"[20h30,22h00] 25" 4
"[13h00,14h30] 25" 4
"[19h30,21h30] 25" 5
"[14h30,16h00] 25" 5
"[16h30,18h00] 25" 5
"[09h30,15h00] 25" 9

And this is my gnuplot code:

set terminal postscript eps color
set output '| epstopdf --filter --outfile=hist.pdf'
set auto x
set yrange [0:10]
set style histogram clustered
set boxwidth 0.95 relative
set style fill transparent solid 0.5 noborder
plot 'hist.dat' using 2:xticlabels(1) with boxes lc rgb'blue90' notitle

Finally this is the graph produced:

enter image description here

like image 391
mariolpantunes Avatar asked Apr 12 '13 15:04

mariolpantunes


2 Answers

Potential Problem 1: xtics overlap

You have a few options to help fix the xtic problem.

1) Rotate the xtics

set xtics rotate by -45

This will set the xtics to print at an angle from top-left to bottom-right.

2) Change the font size

set xtics font ",4"

You could make the font size tiny but unreadable.

3) add a gap between the bars of the graph

set style histogram gap 4

4) Change the data file

If you have control over the data file, you could try inserting some newlines into the xtic labels, e.g.

"17h30\n19h00\n25" 1

Potential Problem 2: xtics too long in general

I'm not quite sure from your question, but you may be running into this issue. Gnuplot has a built-in limit for the number of characters in a label, which is set to 50 in older versions of gnuplot and is 200 more recently. The post I linked to includes a workaround, which is to compile a version of gnuplot with an increased MAX_ID_LEN constant.

like image 133
andyras Avatar answered Nov 10 '22 15:11

andyras


I had a similar issue, but in my case the labels where taken from two columns (a stringcolumn(1) and a numeric column(2)), while y-data in 3-rd column.

I split the labels in two using newline "\n"

using 2:3:xticlabels(stringcolumn(1) . "\n\n" . stringcolumn(2)) 

Basically inside xticlabels() you can give any string expression, for example i also needed some numeric formatting for which i used instead of stringcolumn(2) the following expression:

gprintf('%1.0t*10^{%S}',column(2))

hope it helps

like image 4
isti_spl Avatar answered Nov 10 '22 15:11

isti_spl