3

I am trying to plot a data file similar to the sample given below albeit much bigger.

1.0   12.0   0.03
2.0    14   0.586
10.0    16   0.798
50.0     18  1.023
250.0   28.9   1.124
1000.0   30.2   1.456

I want to plot column 1 with 3 while column 2 will be my upper axis ticks. enter image description here The code the given below:

reset
set logscale x
set logscale y
set xtics nomirror
set xtics (1 ,100, 1000)

set x2tics (1, 100, 1000)#(x2tics is not changing)

set autoscale xfix
set autoscale x2fix
set xlabel 'x'
set ylabel 'y'
set x2label 'm'

plot 'data_test.txt' using 1:3:x2tic(2) with linespoints ps 2 lw 2 title 'y wrt x'   

The initial ticks are all overlapping and I want to reduce the ticks. However, changing x2tics is not fixing the issue. Kindly help.

Archimedes
  • 365
  • 3
  • 15

1 Answers1

1

You are missing a set logscale x2.

Full code:

reset

set logscale x
set logscale y
set logscale x2

set xtics nomirror
set xtics (1 ,100, 1000)


# The next line would plot a confusing 100 between 18 and 28.9,
# so I commented it out
# set x2tics (1, 100, 1000)#(x2tics is not changing)

# But we have to enable x2tics
set x2tics

set autoscale xfix
set autoscale x2fix
set xlabel 'x'
set ylabel 'y'
set x2label 'm'

plot 'data_test.txt' using 1:3:x2tic(2) with linespoints ps 2 lw 2 title 'y wrt x'

The result:

without overlapping x2tics


Update

To reduce the number of x2tics, I would try two plots: The first plots the data points, the second one only plots the x2tics:

plot 'data_test.txt' using 1:3 with linespoints ps 2 lw 2 title 'y wrt x', \
     'data_test.txt' using 1:(NaN):x2tic(2) every 2 notitle

Here, NaN "hides" the data points, and every 2 skips every 2nd line.

maij
  • 4,094
  • 2
  • 12
  • 28
  • Thanks for your solution. But this seems strange as I try setting logscale x2, the ticks seem to get displaced! Uploaded here: https://imgur.com/WuP1Yuq. I am using Gnuplot version 5.2 patchlevel 2. Moreover, this not the kind of solution I was looking for. I need, if possible, control over ticks frequency as I have many closely spaced data point. – Archimedes Sep 10 '19 at 08:45
  • @Archimedes Interesting. I copy and paste your data to `data_test.txt`, and I copy my script to `script.plt`. Then I open gnuplot and call `load 'script.plt` and I get the picture which is included in the answer. I have confirmed this right now, could you also please double check? I am using gnuplot 5.0 patchlevel 2. – maij Sep 11 '19 at 18:28
  • I have added an possibility for reducing the number of tics. You also should have a look at https://stackoverflow.com/questions/19121823/gnuplot-plot-x2-axis-with-respect-to-x1-axis. – maij Sep 11 '19 at 18:53