Reputation: 173
My data file is given below
ExpData.dat
### Units mg/g
### Col 1-4: Users 1-4
### Col 5-8: Standard 1
### Col 9-12: Standard 2
### Col 13-16: Standard 3
### Col 17-20: Standard 4
### Col 21-24: Standard 5
### Col 25-28: Standard 6
## User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4
User-1 User-2 User-3 User-4 10.07 9.92 9.79 9.68 19.78 19.90 19.38 19.22 39.43 38.35 37.55 37.75 48.95 47.81 46.56 46.23 56.11 56.32 55.04 55.44 67.98 69.39 67.98 67.64
User-1 User-2 User-3 User-4 10.08 9.91 9.82 9.63 19.79 19.92 19.34 19.22 39.45 38.37 37.57 37.70 48.90 47.79 46.58 46.27 56.13 56.35 55.18 55.51 68.02 69.45 67.78 67.60
User-1 User-2 User-3 User-4 10.02 9.92 9.76 9.64 19.75 19.91 19.33 19.25 39.41 38.41 37.58 37.68 48.92 47.81 46.63 46.24 56.13 56.41 55.27 55.63 68.00 69.38 67.86 67.68
User-1 User-2 User-3 User-4 10.04 9.92 9.86 9.64 19.79 19.93 19.33 19.21 39.45 38.35 37.57 37.61 48.92 47.78 46.68 46.26 56.13 56.34 55.02 55.57 68.04 69.42 67.68 67.83
User-1 User-2 User-3 User-4 10.01 9.89 9.76 9.69 19.74 19.94 19.30 19.20 39.47 38.34 37.53 37.78 48.97 47.81 46.74 46.22 56.18 56.37 55.10 55.46 68.12 69.41 67.76 67.44
User-1 User-2 User-3 User-4 10.06 9.88 9.79 9.71 19.79 19.94 19.35 19.20 39.49 38.41 37.58 37.72 48.90 47.81 46.64 46.29 56.14 56.35 54.98 55.50 68.12 69.38 68.03 67.72
Now I wish to have a scatter plot with User-1, User-2, User-3 and User-4 as x-tics. Seems to be quite easy when plotting a histogram but I am getting a small issue while plotting the scatter plot. The test code for plotting the data only for User-1 and User-2 is given below (User-1 and User-2 as x-tics)
##
##
reset session
##
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 4in,3in
set output "ExpData.eps"
#
set xtics out scale 1.5
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg U/g" font ",16"
set key inside top right title "Experimental Data" font ",14"
set yrange [0:75]
#
plot 'ExpData.dat' u 5:xtic(1) w points pt 10 ps 1.50 lt rgb "#0000FF" notitle, \
'' u 9:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#006400" notitle, \
'' u 13:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 17:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 21:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FF0000" notitle, \
'' u 25:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FFD700" notitle, \
###
'' u 6:xtic(2) w points pt 8 ps 1.50 lt rgb "#0000FF" notitle, \
'' u 10:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#006400" notitle, \
'' u 14:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 18:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 22:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#FF0000" notitle, \
'' u 26:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#FFD700" notitle, \
###
The code ends with the error "invalid command". Can anybody suggest if the data file or the code has a problem.
Revision of question after response of @theozh
What I need is
i). There should be only 4 tics in x-axis; User-1, User-2, User-3 and User-4.
ii). For User-1, there should be 6 sets of 6 points plotted at different y-range (Col 5, 9, 13, 17, 21 and 25 for User-1). For each column, pointtype
is already defined in the code. For example for User-1
plot 'ExpData.dat' u 5:xtic(1) w p pt 10 ps 1.50 lt rgb "#0000FF", \
'' u 9:xtic(1) w p pt 10 ps 1.50 lt rgb "#006400", \
'' u 13:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 17:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 21:xtic(1) w p pt 10 ps 1.50 lt rgb "#FF0000", \
'' u 25:xtic(1) w p pt 10 ps 1.50 lt rgb "#FFD700", \
But it leads to 6 tics of User-1 and not a single tic.
iii). Complete code is given below but it gives 6 tics of User-4 only.
##
##
reset session
##
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 4in,3in
set output "ExpData.eps"
# FOR CUSTOM LINESTYLES
set style line 1 lt 2 lw 4 lc rgb "#0000FF"
set style line 2 lt 2 lw 4 lc rgb "#006400"
set style line 3 lt 2 lw 4 lc rgb "#9932CC"
set style line 4 lt 2 lw 4 lc rgb "#120A8F"
set style line 5 lt 2 lw 4 lc rgb "#FF0000"
set style line 6 lt 2 lw 4 lc rgb "#FFD700"
set style line 7 lt 2 lw 4 lc rgb "#8470FF"
set style line 8 lt 2 lw 4 lc rgb "#5D478B"
set style line 9 lt 2 lw 4 lc rgb "#9370DB"
set style line 10 lt 2 lw 4 lc rgb "black"
set key samplen 4 spacing 1.4 font ",14" width -2
#
set xtics out scale 1.5
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg/g" font ",16"
set key inside bottom right spacing 1.35 font ",12" noautotitle
set key title "Experimental Data" font ",14"
set yrange [0:75]
#
plot 'ExpData.dat' u 5:xtic(1) w p pt 10 ps 1.50 lt rgb "#0000FF", \
'' u 9:xtic(1) w p pt 10 ps 1.50 lt rgb "#006400", \
'' u 13:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 17:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 21:xtic(1) w p pt 10 ps 1.50 lt rgb "#FF0000", \
'' u 25:xtic(1) w p pt 10 ps 1.50 lt rgb "#FFD700", \
'' u 6:xtic(2) w p pt 8 ps 1.50 lt rgb "#0000FF", \
'' u 10:xtic(2) w p pt 8 ps 1.50 lt rgb "#006400", \
'' u 14:xtic(2) w p pt 8 ps 1.50 lt rgb "#9932CC", \
'' u 18:xtic(2) w p pt 8 ps 1.50 lt rgb "#9932CC", \
'' u 22:xtic(2) w p pt 8 ps 1.50 lt rgb "#FF0000", \
'' u 26:xtic(2) w p pt 8 ps 1.50 lt rgb "#FFD700", \
'' u 7:xtic(3) w p pt 6 ps 1.50 lt rgb "#0000FF", \
'' u 11:xtic(3) w p pt 6 ps 1.50 lt rgb "#006400", \
'' u 15:xtic(3) w p pt 6 ps 1.50 lt rgb "#9932CC", \
'' u 19:xtic(3) w p pt 6 ps 1.50 lt rgb "#9932CC", \
'' u 23:xtic(3) w p pt 6 ps 1.50 lt rgb "#FF0000", \
'' u 27:xtic(3) w p pt 6 ps 1.50 lt rgb "#FFD700", \
'' u 8:xtic(4) w p pt 4 ps 1.50 lt rgb "#0000FF", \
'' u 12:xtic(4) w p pt 4 ps 1.50 lt rgb "#006400", \
'' u 16:xtic(4) w p pt 4 ps 1.50 lt rgb "#9932CC", \
'' u 20:xtic(4) w p pt 4 ps 1.50 lt rgb "#9932CC", \
'' u 24:xtic(4) w p pt 4 ps 1.50 lt rgb "#FF0000", \
'' u 28:xtic(4) w p pt 4 ps 1.50 lt rgb "#FFD700"
### End of code
Upvotes: 1
Views: 319
Reputation: 25749
Your problem is here:
'' u 25:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FFD700" notitle, \
###
'' u 6:xtic(2) w points pt 8 ps 1.50 lt rgb "#0000FF" notitle, \
The character \
continues line 1. If you start line 2 with #
, this will be a comment.
If you do not end this line with \
, line 3 will be a new command, but '' u 6:...
is an invalid command because it is not "connected" anymore to the original plot command. But even if you add a \
at the end of line 2, the whole rest of the lines will be interpreted as a comment. Check help comments
.
So, remove the ###
. It might be nice for visual structuring and formatting but does not work within a plot command (only at the very end).
By the way, you can shorten some commands which makes you plotting command shorter and clearer.
xticlabels()
--> xtic()
with points
--> w p
set key noautotile
instead of repeating notitle
in each sub-plot command.That's how you remove the error. But something else on your plot seems to be incorrect. Maybe you can explain in more detail how you want the xtic labels with the users.
Edit: (after OP editing the question)
You can use loops in plot commands which might make your life easier and shorter. You can loop the user and the number of the plot for each user. You define some functions for your pointtype, the color and the data column. And then use variable pointtype pt var
and variable linecolor lc rgb var
. Check help variable
. I tried to do this with your data.
Although, I doubt you want to apply the same color 0x9932cc
twice, but this can easily be changed.
Code:
### plot command does not allow for commented lines inbetween
reset session
$Data <<EOD
## User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4
User-1 User-2 User-3 User-4 10.07 9.92 9.79 9.68 19.78 19.90 19.38 19.22 39.43 38.35 37.55 37.75 48.95 47.81 46.56 46.23 56.11 56.32 55.04 55.44 67.98 69.39 67.98 67.64
User-1 User-2 User-3 User-4 10.08 9.91 9.82 9.63 19.79 19.92 19.34 19.22 39.45 38.37 37.57 37.70 48.90 47.79 46.58 46.27 56.13 56.35 55.18 55.51 68.02 69.45 67.78 67.60
User-1 User-2 User-3 User-4 10.02 9.92 9.76 9.64 19.75 19.91 19.33 19.25 39.41 38.41 37.58 37.68 48.92 47.81 46.63 46.24 56.13 56.41 55.27 55.63 68.00 69.38 67.86 67.68
User-1 User-2 User-3 User-4 10.04 9.92 9.86 9.64 19.79 19.93 19.33 19.21 39.45 38.35 37.57 37.61 48.92 47.78 46.68 46.26 56.13 56.34 55.02 55.57 68.04 69.42 67.68 67.83
User-1 User-2 User-3 User-4 10.01 9.89 9.76 9.69 19.74 19.94 19.30 19.20 39.47 38.34 37.53 37.78 48.97 47.81 46.74 46.22 56.18 56.37 55.10 55.46 68.12 69.41 67.76 67.44
User-1 User-2 User-3 User-4 10.06 9.88 9.79 9.71 19.79 19.94 19.35 19.20 39.49 38.41 37.58 37.72 48.90 47.81 46.64 46.29 56.14 56.35 54.98 55.50 68.12 69.38 68.03 67.72
EOD
set xtics out scale 1.5
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg U/g" font ",16"
set key inside top right title "Experimental Data" font ",14" noautotitle
set yrange [0:75]
myPoints(n) = int(word("10 8 6 4",n)) # different pointtypes
myColor(n) = int(word("0x0000ff 0x006400 0x9932cc 0x9932cc 0xff0000 0xffd700",i))
myColumn(user,n) = column(user + n*4)
set xrange[0.5:4.5]
plot for [user=1:4] for [i=1:6] \
$Data u (user):(myColumn(user,i)):(myPoints(user)):(myColor(i)):xtic(user) \
w p pt var ps 1.50 lc rgb var
### end of code
Result:
Upvotes: 1