X-Axis Value on Gnuplot

x-axis value on gnuplot

Instead of calling:

plot "time_mem_access.dat" using 1:2 title "cache access 1", \
"" using 1:3 title "cache access 2"

You can try:

plot "time_mem_access.dat" using 1:2:xtic(1) title "cache access 1", \
"" using 1:3:xtic(1) title "cache access 2"

Which will give you the following plot:
Sample Image

However you might want to take a log of the x values:

plot "time_mem_access.dat" using (log($1)):2:xtic(1) title "cache access 1", \
"" using (log($1)):3:xtic(1) title "cache access 2"

Which would give you:
Sample Image

Gnuplot plot data with text column as X axis


$data << EOD
ls 10
cd 5
cut 12
awk 7
EOD

# this is all just plot layout stuff; customize to taste
unset border
set tics scale 0
set xzeroaxis
set title "x coord = line number"

# use line number for x coordinate, column 1 for tic label
plot $data using 0:2:xticlabel(1) with impulse

Sample Image

gnuplot: change value of x-axis

For this task you can use the xticlabels command in the using statement (see also the very recent question gnuplot arbitrary labeling x - axis):

set xlabel "Letters"
set ylabel "Percentages"
set style data lines
plot "frequency.txt" using 2:xticlabels(1) t "Website", \
"" using 3 t "Python"

with the result (using 4.6.5):

Sample Image

x axis on top of graph in gnu plot

still guessing what exactly you want. Maybe we'll find out faster with this example.

reset session

$Data <<EOD
# x2 x1 y
20 1.2e-2 1
40 3.0e-3 2
60 1.4e-3 3
EOD

set key top center
set xtics nomirror
set x2tics nomirror

plot $Data u ($1*2):3 axes x2y1 w lp pt 7 title "y-data vs. x2-axis", \
'' u 2:3 axes x1y1 w lp pt 7 title "y-data vs. x1-axis"

Result:

Sample Image

Edit:

You can link x1 and x2 axes via a function (in the example below conversion between nm and eV) and then set your x2tics as desired.

  1. Graph1: corresponding "odd" values from x1,
  2. Graph2: "even" values by given interval x2tics 0.2,
  3. Graph3: manual setting of x2tics.

Example:

### linked axes x1, x2
reset session

set xlabel "Wavelength / nm"
set xtics nomirror
set x2label "Energy / eV"
set x2tics nomirror
set link x via 1239.8/x inverse 1239.8/x

set ylabel "Intensity / a.u."
set ytics 0.2
set samples 400
Spectrum(x) = exp(-(x-500)**2/(400))

set xrange[380:780]

set multiplot layout 3,1
set format x2 "%.2f"
plot Spectrum(x) w l title "Spectrum"

set format x2 "%.1f"
set x2tics 0.2
replot

set x2tics ()
myTics = "1.7 1.8 1.9 2.0 2.1 2.3 2.5 2.7 3.0"
do for [i=1:words(myTics)] { set x2tics add (word(myTics,i) real(word(myTics,i))) }
replot

unset multiplot
### end of code

Result:

Sample Image

gnuplot: I need to plot on x-axis only 2 values

Ethan suggestion works

set xtics (value1, value2)

Thank you!

How to label the x axis with exact values

To remove the key, use unset key.

The markers at the bottom of the graph are called xtics. If you want them to appear every 1, rather than every 2, then you could use set xtics 1. Depending on exactly what you wanted to do, you can customise the xtics even more. In gnuplot if you do help xtics there's plenty of information on that.

To change the colour of your boxes, you can use the lc (line colour) property. I have used a hexadecimal #RRGGBB format but you can also use names of colours like green, blue, etc. Look at help linecolor for more info on that.

Incorporating all of those changes into your script:

set xlabel "full configuration time in msec"
set ylabel "Task rejection rate (%)"
set boxwidth 0.5
set style fill solid

unset key
set xtics 1

plot "data.data" using 1:2 with boxes lc rgb '#52bb23'

plot with changes made

By the way, I used the pngcairo terminal rather than the jpeg one as I think it looks better. Try set term to see what terminals are available to you.

Generate my own X-axis values / Replace X-axis with own values

You can always use the line number to generate such data. It can be referenced in the "using" specifier as (pseudo)column zero, e.g.

t(n) = 0.2 * n
plot dataf using (t($0)):2 w l

("line number" means number of lines with valid data. Comments, blanks are not counted.)

As you saved the line number in the first column, you can of course also use that instead.

The number of consecutive datablocks (separated by single blank lines) and datasets (separated by double blank lines, see "help index") can be referenced as columns number "-1" and "-2", btw. See "help pseudocolumn".

Color x-axis or line depending on y-value

As I understand, you want a line graph and some horizontal line with some color depending on value in the 3rd column.
So, why not plotting a bar graph? Check the example below which can be adapted to your special needs.

Code:

### apply shades of colors from a column
reset session

# create some test data
set print $Data
do for [i=1:18] {
print sprintf("%g %g %g", i/10., rand(0)*10+10, i)
}
set print

set palette defined ( 0 "#aa0000", 1 "#ee0000", 1.99 "#ffaaaa", \
2 "#00aa00", 3 "#00ee00", 3.99 "#aaffaa", \
4 "#0000aa", 5 "#0000ee", 5.99 "#aaaaff" ) maxcolors 18

set style fill solid 1.0
set boxwidth 0.8 relative
set xtics out
set yrange[0:30]
set cbrange[1:18]
set cbtics ()
do for [i=1:18] {
set cbtics add (sprintf("%g",i) i/18.*17+0.5)
}
set key noautotitle

plot $Data u 1:2:3 w boxes lc palette
### end of code

Result:

Sample Image

Code: (alternatively, a line graph with color bars at the bottom)

### apply shades of colors from a column
reset session

# create some test data
set print $Data
do for [i=1:18] {
print sprintf("%g %g %g", i/10., rand(0)*10+10, i)
}
set print

set palette defined ( 0 "#aa0000", 1 "#ee0000", 1.99 "#ffaaaa", \
2 "#00aa00", 3 "#00ee00", 3.99 "#aaffaa", \
4 "#0000aa", 5 "#0000ee", 5.99 "#aaaaff" ) maxcolors 18

set style fill solid 1.0
set boxwidth 0.8 relative
set xtics out
set yrange[0:30]
set grid x,y
set cbrange[1:18]
set cbtics ()
do for [i=1:18] {
set cbtics add (sprintf("%g",i) i/18.*17+0.5)
}
set key noautotitle

plot $Data u 1:2 w lp pt 7 lc "black", \
'' u 1:(0.5):3 w boxes lc palette
### end of code

Result:

Sample Image

How do I edit the time values on the x-axis to start from zero when using gnuplot?

The following example uses the newer gnuplot date time syntax (see help timecolumn), e.g. timecolumn(1,myTimeFmt) and set format x "%H:%M" time.

In order to normalize your time series to the first data point you have to store this time into a variable, e.g. t0 which you can "re-use" in successive plot commands from the same datafile.

Note the different time format for the x axis: "%H:%M" for day time and "%tH:%tM" for hours exceeding 24 hours or minutes exceeding 60 minutes, see help time_specifiers.

Edit:

  • for better readability of the plot command, I "outsourced" the normalization into a function Normalize(). But note that t=0 is still required at the beginning of the plot command.
  • in case you have some (uncommented) header lines, you need to skip them via skip <number of header lines>.

Code:

### normalize time data relative to start time
reset session

myTimeFmt = "%Y-%m-%d %H:%M:%S"

# create some test data
set table $Data
plot '+' u (strftime(myTimeFmt,time(0) + $1*3600*2)):(cos($1)) w table
unset table

# function to normalize time column to first value
Normalize(c) = (t==0?(t0=timecolumn(c,myTimeFmt),t=1):NaN, timecolumn(c,myTimeFmt)-t0)

# in case there are uncommented header lines skip them
SkipHeaderLines = 0

set multiplot layout 2,1

set format x "%Y\n%m-%d\n%H:%M" time
plot $Data u (timecolumn(1,myTimeFmt)):3 skip SkipHeaderLines w l ti "absolute time"

set format x "%tH:%tM" time
plot t=0 $Data u (Normalize(1)):3 skip SkipHeaderLines w l ti "relative time"
unset multiplot
### end of code

Result:

Sample Image



Related Topics



Leave a reply



Submit