deb97
deb97

Reputation: 61

plotting data with too many zero on x axis

I have this data1.dat data that I'd plot using gnuplot.

x        y
0.007   3.09216
0.008   3.60607
0.009   5.86643

then I tried to plot this with this plot script

set terminal svg size 400,300 enhanced fname 'arial'  
set output 'out2.png'

set xlabel 'diameter'
set ylabel 'number density'
set title 'density number plot'
plot  "data1.dat" using 3:4 title "" with lines

and the output in the x axis was like this enter image description here

how to convert the number data on the x axis so it only shows only for example 7 or 8 only? this is an example and probably my data would getting bigger, so i can't change the data on data1.dat one by one in the x column, thanks in advance

Upvotes: 0

Views: 178

Answers (1)

theozh
theozh

Reputation: 26200

Apparently, gnuplot's tic algorithm doesn't take the length of the ticlabels into account. That's why the numbers are overlapping. You can do the following:

  • set the xtic increment manually to avoid overlap, e.g. set xtic 0.0005

  • multiply your values by a factor, e.g. 1000, especially if you have meters you can display millimeters, i.e. ($1*1000) which is identical to (column(1)*1000).

Code:

### avoid overlap of tic labels
reset session

$Data <<EOD
x        y
0.007   3.09216
0.008   3.60607
0.009   5.86643
EOD

set ytics 1
set multiplot layout 3,1

    set xlabel 'diameter / m'
    plot  $Data using 1:2 w l notitle

    set xlabel 'diameter / m'
    set xtic 0.0005
    plot  $Data using 1:2 w l notitle

    set xlabel 'diameter / mm'
    set xtics 0.2
    plot  $Data using ($1*1000):2 w l notitle

unset multiplot
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions