1
votes

I have the following data in data file test1.txt:

A   36  1
A   35  1
B   48  2
B   37  2
B   15  2
C   36  3
C   25  3

and test2.txt

A   16  1
A   25  1
B   38  2
B   45  2
C   36  3

the plotting is done as:

dat1="test1.txt"
dat2="test2.txt"
plot dat1 u ($3-0.2):2 w p t 'title 1', \
     dat2 u ($3+0.2):2 w p t 'title 2', \
     dat1 using 3:(0):xticlabels(1):x2ticlabels(1) notitle, \
     dat2 using 3:(0):xticlabels(1):x2ticlabels(1) notitle

The whole point is to have the labels from the first column on the x axis. The issue is that the last two parts of plot

dat1 using 3:(0):xticlabels(1):x2ticlabels(1) notitle, \
dat2 using 3:(0):xticlabels(1):x2ticlabels(1) notitle

produce points at y=0. And because I cannot (or I do not know how to) use

plot dat1 u ($3-0.2):2:xticlabels(1) w p t 'title 1'

(since it plots the label at x coordinate $3-0.2 and not at $3, which i require), I am forced to do two more dummy plots, but they produce points and I do not know how to effectively avoid this other than shifting the outside of the range of the plot by e.g. dat1 using 3:(0):xticlabels(-1):x2ticlabels(-1) in the case of plotting only positive values. Is there any good way of solving this?

2
Problem solved? Question answered? Any feedback to any of the answers would be appreciated! - theozh

2 Answers

0
votes

I don't really understand what you are trying to do with your data, however if you want to make the points over the x axis invisible you can set the line color to full transparency for the last two plots:

dat1 using 3:(0):xticlabels(1):x2ticlabels(1) linecolor "#FFFF0000" notitle, \
dat2 using 3:(0):xticlabels(1):x2ticlabels(1) linecolor "#FFFF0000" notitle

In recent versions of Gnuplot (link) it is possible to add transparency, in this particular case you want to set full transparency to the line color so that the points are invisible. The color format and transparency can be set using the hexadecimal notation #AARRGGBB where AA (alpha) controls how transparent the color is, for full transparency you want FF which is equivalent to 255, notice how my line color is RED but because is completely transparent we don't see it. Plot with Full Transparency

0
votes

My understanding of your question is the following: You have some data which you want to shift in x by +/-0.2 but the corresponding tic shouldn't be shifted. You've been almost there. Of course, there are points at y=0 because you tell gnuplot to do so. What you mean with "invisible" could of course be also achieved by fully transparent points, but the easier way is probably to "plot" the points at NaN, i.e. nowhere.

Code:

### plotting data with offset and tic without offset
reset session
set colorsequence classic

$Data1 <<EOD
A   36  1
A   35  1
B   48  2
B   37  2
B   15  2
C   36  3
C   25  3
EOD

$Data2 <<EOD
A   16  1
A   25  1
B   38  2
B   45  2
C   36  3
EOD

set offsets 0.5,0.5,0.5,0.5
set link x2
set x2tics

plot $Data1 u ($3-0.2):2 w p pt 7 t 'title 1', \
     $Data2 u ($3+0.2):2 w p pt 7 t 'title 2', \
     $Data1 using 3:(NaN):xtic(1):x2tic(1) notitle, \
     $Data2 using 3:(NaN):xtic(1):x2tic(1) notitle
### end of code

Result:

enter image description here