2
votes

I'm trying to plot the data of 100x11 array in plot using gnuplot. I created a .gnu file to generate plot but unable to get jitter plot.

I'm using the below code

set terminal pngcairo size 1280,800 enhanced font 'Helvetica,24'
set output "coin_flip.png"

# Title, axis label, range and ticks
set title "Jitter plot of data from coin flip experiment"
set xlabel "Fairness (p)"
set ylabel "# of heads in 10 tosses"
set xrange [-0.1:1.1]
set yrange [-1:11]

# Line styles
set style line 1 lt -1 lw 4 pt 5 lc rgb "red"
set style line 2 lt -1 lw 4 pt 7 lc rgb "blue"
set style line 4 lt -1 lw 4 pt 7 lc rgb "green"
set style line 5 lt -1 lw 4 pt 13 lc rgb "purple"
set style line 6 lt -1 lw 8 pt 13 lc rgb "black"

# Function definitions and curve fits
set fit logfile 'coin_flip.log'

#Fit
plot "coin_flip.dat" using 1:2 ti "Fairness(p) vs # of Heads" ls 1

I'm getting below result

enter image description here

But I'm trying to get as the below plot

enter image description here

Below is the graph that I obtain after using

set jitter

enter image description here

Can you please help me in plotting?

2
.dat file is generated using Matlabuser1215486

2 Answers

0
votes

You need to use the set jitter option on gnuplot. The following code:

set terminal png
set out "tmp.png" 

set multiplot layout 1,2
unset key

set title "no jitter"
plot x w p

set jitter
set title "jitter"
plot x w p

Produces this:

gnuplot jitterg

You can get fancy on the jitter patterns and other options typing help jitter on your gnuplot console. Also have a look at these examples. Hope it helps!

0
votes
# coin_flip.gnu
#
# gnuplot instructions to fit and plot the data in coin_flip.dat
#
# Usage:
# gnuplot coin_flip.gnu

# Terminal and output settings
set terminal pngcairo size 1280,800 enhanced font 'Helvetica,24'
set output "coin_flip.png"

# Title, axis label, range and ticks
set title "Jitter plot of data from coin flip experiment"
set xlabel "Fairness (p)"
set ylabel "# of heads in 10 tosses"
set xrange [-0.1:1.1]
set yrange [-1:11]

# borders
set boxwidth 0.1 absolute
set xzeroaxis
set yzeroaxis
set zzeroaxis

# grid
set style line 12 linecolor rgb '#808080' linetype 0 linewidth 1
set grid back linestyle 12
set grid xtics ytics mxtics

#point size of the data points
set pointsize 15

#puts the key on the top right
set key bottom right

# Function definitions and curve fits
set fit logfile 'coin_flip.log'

set style line 1 lc rgb "red" pt 6
# set style line 2 lt -1 lw 4 pt 7 lc rgb "blue"
# set style line 4 lt -1 lw 4 pt 7 lc rgb "green"
# set style line 5 lt -1 lw 4 pt 13 lc rgb "purple"
# set style line 6 lt -1 lw 8 pt 13 lc rgb "black"

#Fit
w=.5
plot "coin_flip.dat" using 1:($2+w*invnorm(rand(0))) ti "P vs Number of Heads" ls 1

The above is working fine to generate jitter plot