1
votes

I am plotting data from a datafile and the data has behaviour that after a while on the x-axis the y-axis start to monotonically decrease and ultimately go to zero (with some very small fluctuations later on).

Hence, I want to offset the y-axis so that those fluctuations are clearly visible. For that I use something like set offsets 0,0,0,0.1. But I have actually written a bash script to generate the plot for me. I just need to provide the datafile name to it. So for each plot I don't want to go into the script and manually set offset value based on the data.

I would like if the offset were determined by gnuplot automatically based on the bin-size on the axis, like the offset is 1*bin-size. So my command could look like :

set offsets 0,0,0,1*$bin_size

Is there any way to achieve this?

Edit:

This is the script I am using.

#!/bin/bash

#Requires that the script be in the same directory as the data files
#sed -n '3001,4000p' fish_data_re.dat > fish_data_re_3k_4k.dat : Can be used to extract data from specific range in data file

DATA_FILE_NAME="abc"
DATA_FILE_TYPE="dat"


#Code to generate normalised files
awk 'NR == FNR {if(max < $2) {max = $2}; next} {$2 = $2 / max; printf "%f\t%f\n", $1, $2}' $DATA_FILE_NAME.$DATA_FILE_TYPE $DATA_FILE_NAME.$DATA_FILE_TYPE > $DATA_FILE_NAME\_normed.$DATA_FILE_TYPE

DATA_FILE_NAME="$DATA_FILE_NAME\_normed"
DATA_FILE_TYPE="dat"

OUTPUT_FILE_TYPE="eps"
OUTPUT_FILE_NAME="$DATA_FILE_NAME\_plot.$OUTPUT_FILE_TYPE"

X_LABEL="Time"
Y_LABEL="Real Classical Fisher Information"
TITLE="Real Classical Fisher Information vs Time"

#Set font size for axis tics
X_TICS_SIZE="6"
Y_TICS_SIZE="6"


gnuplot <<- MULTI_LINE_CODE_TAG

set xlabel "$X_LABEL"
set ylabel "$Y_LABEL"

#Following command allows the printing of underscore from name of data file in plot
set key noenhanced

set title "$TITLE" 

set xtics font ", $X_TICS_SIZE"
set ytics font ", $Y_TICS_SIZE"

set xtics nomirror
set ytics nomirror

#set ytics format "%.22g"
set ytics format "%0.s*10^{%L}"
#set xtics format "%t"



set multiplot

#------The big-plot------

set title "$TITLE" 
set offsets 0,0,0,0.01

#Following plots only data from line 1 to line 100
#plot "<(sed -n '1,100p' $DATA_FILE_NAME.$DATA_FILE_TYPE)" u 1:2 notitle w l lc "red" lw 2 
plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2

#------The sub-plot------

unset title
unset offsets

set origin 0.25,0.3
set size 0.45,0.45
set xrange [30:60]
set yrange [-0.01:0.01]
unset xlabel
unset ylabel
#unset label

plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2

unset multiplot

set term "$OUTPUT_FILE_TYPE"
set output "$OUTPUT_FILE_NAME"

replot

MULTI_LINE_CODE_TAG

exit

As you can see I need to provide the offset manually.

Here is the plot I am getting.

enter image description here The y-axis here got offset by -0.002 -0.2. I want to automate this thing and want gnuplot to always use the the offset as the size of a bin (which I define as the distance between successive tics).

(If this is a trivial question I apologise in advance, I am quite new to gnuplot.)

1
it's not fully clear to me what you want. What do you mean with bin-size? If you want to show small fluctuations towards zero maybe logscale might be an option? Please show some example data, example graph and some code. - theozh
@theozh Updated with the required code and graph. - Nitin

1 Answers

1
votes

I guess I still don't understand your exact problem. By the way, your offset it -200e-3 = -0.2 not -0.002. Is your data always between 0 and 1? You could set the offsets depending on the graph (check help offsets)

set offsets 0,0,0, graph 0.2

In general, why not using logarithmic scale? With this you will be able to see all small features in your data.

Code:

### linear scale vs logarithmic scale
reset session 

# Gauss curve by specifing Amplitude A, position x0 and width via FWHM
GaussW(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))

# create some test data
set xrange[0:100]
set samples 500
set table $Data
    plot '+' u 1:(GaussW($1,5,1,2.5) + GaussW($1,40,7e-3,2) + GaussW($1,47,8e-4,5) + 2e-4) w table
unset table

set multiplot layout 1,2
    set offset 0,0,0, graph 0.2
    set yrange[-0.02:1]
    plot $Data u 1:2 w l title "linear y-scale"

    set logscale y
    set yrange[1e-4:1]
    plot $Data u 1:2 w l title "logarithmic y-scale"
unset multiplot
### end of code

Result:

enter image description here