Machang
Machang

Reputation: 25

How to avoid the points (y-axis) in the graph?

I have this graph.

The Y axis is labeled D, A, Q, and F. The X axis is labeled 0 through 12. The X axis values are repeated in columns 1 and 7. Why are the points of the y-axis (black color) are written in the graph?

My code:

xcoord(N) = (N)
ycoord(N) = (column(0)+1)
symbol(N) = strcol(N) ne "/" ? strcol(N) : "/"
array colors = [0xFF0000, 0x0000FF, 0xFFFF00, 0x00FF00, 0xC080FF]
array symbol = ["/", "5", "g", "3", "o"]
color(sym) = sum [i=1:5] (symbol[i] eq sym ? colors[i] : 0)
plot for [N=1:6] 'test.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)):(color(strcol(N))) with labels tc rgb variable font ":Bold" notitle, \
for [N=1:6] 'test1.txt' using (xcoord(N)+6):(ycoord(N)):(symbol(N)):(color(strcol(N))) with labels tc rgb variable font ":Bold" notitle
set xrange [0:12]
set yrange [0:5]
set ytics ("D" 1, "A" 2, "Q" 3, "F" 4)

To draw the graph, I read two files. Both files have the same y-axis. How can I remove the points?

test.txt

# 1 2 3 4 5
D / / 5 / g
A / o / / 5
Q / / o / 5
F / / 3 g 3

test1.txt

# 6 7 8 9 10
D 5 / 5 / g
A / o / g 5
Q / o o / 5
F / / 3 5 3

Upvotes: 2

Views: 56

Answers (1)

theozh
theozh

Reputation: 25694

You are telling gnuplot to plot the y-tic labels in the graph because you are looping from column 1 to column 6. Furthermore, you don't have to set the ytics manually, you can do it automatically in the plot command :ytic(1). If you use word() (check help word) you can avoid arrays and the code should even run with gnuplot 4.x (which did not have arrays). By the way, if you want to set ranges and tics you have to do this before the plot command.

Code:

### plotting colored labels
reset session

$Data1 <<EOD
#   1 2 3 4 5
D   / / 5 / g
A   / o / / 5
Q   / / o / 5
F   / / 3 g 3
EOD

$Data2 <<EOD
#   6 7 8 9 10
D   5 / 5 / g
A   / o / g 5
Q   / o o / 5
F   / / 3 5 3
EOD

myColors         = "0xff0000 0x0000ff 0xffff00 0x00ff00 0xc080ff"
myColor(i)       = int(word(myColors,i))
mySymbols        = "/ 5 g 3 o"
mySymbol(i)      = word(mySymbols,i)
myColorLookup(s) = sum [i=1:5] (s eq mySymbol(i) ? myColor(i) : 0)

myOffset = 5     # x-offset between the two files
set key noautotitle
set offset 0.5, 0.5, 0.5, 0.5    # add some margin to the border

plot for [c=2:6] $Data1 u (c-1):         0:c:(myColorLookup(strcol(c))):ytic(1) w labels tc rgb var font ":Bold", \
     for [c=2:6] $Data2 u (c-1+myOffset):0:c:(myColorLookup(strcol(c)))         w labels tc rgb var font ":Bold"
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions