Upper axis values through linking with lower axis gnu plot

  • Thread starter Thread starter CAF123
  • Start date Start date
  • Tags Tags
    Axis Plot
AI Thread Summary
The discussion focuses on linking the upper axis (x2) with the lower axis (x) in Gnuplot to display corresponding values based on a defined relationship: x2 = 2*c**2/(2*x**2-c**2), where c=3.1. The user is attempting to print values on the upper axis for specific lower axis values (x=100, 1000) but is struggling to achieve meaningful output. The issue arises from misunderstanding how the set link command functions, as it does not mirror tick marks between the two axes. Instead, the upper axis generates its own set of ticks. Suggestions for resolving the issue include using the nomirror option for tics and experimenting with different linking methods. The user has also indicated progress in finding a solution outside of C++.
CAF123
Gold Member
Messages
2,918
Reaction score
87
I am trying to link the upper axis with the lower axis in gnu plot, that is print out values on the upper axis given a relationship between the upper axis, x2, quantities and the lower axis, x, ones. The relationship between them is

Code:
x2 = 2*c**2/(2*x**2-c**2)
with
Code:
c=3.1
The following should be sufficient

Code:
    set xlabel "Quantity lower"
    set xtics nomirror
    set x2label "Quantity Upper"
    set x2tics nomirror
    set link x2 via 2*(3.1)**2/(2*x**2-(3.1)**2) inverse sqrt((3.1)**2*(2+x)/2/x)

    #set link x via 1239.8/x inverse 1239.8/x

    set ylabel "Quantity y"
    set ytics 0.2
    set samples 400
    Spectrum(x) = exp(-(x-500)**2/(400))

    set xrange[30:2000]

    set format x2 "%.2f"
    plot Spectrum(x) w l title "Spectrum"

I've also log formatted the x-axis via

Code:
set logscale x
set format x "10^{%L}"

but regardless of whether I include the log formatting I am unable to get any meanginful values printed out on the upper axis. (The function for y is for illustrative purposes only, the value for y in my actual script relies on reading in data from a file)

I'd like to print out values on the upper axis for two values of x=100, 1000 say. Not sure if this is the right place for this but thanks for any comments!
 
Technology news on Phys.org
@Mark44 Hi, looks similar but not quite the same - there they are plotting two different relationships (x2 v.s y2) and (x1 v.s y1). All I want to do, and I hoped it would have been trivial to do, is to link the x2 axis (upper axis) with the x-axis (lower axis). That is, for a given tick mark on the x-axis with value ##X##, I want to print out the corresponding tick mark on the x2 axis with value ##x2(X)##, where
Code:
x2 = 2*c**2/(2*x**2-c**2)
as given in my OP. Does my question make sense?
 
CAF123 said:
That is, for a given tick mark on the x-axis with value ##X##, I want to print out the corresponding tick mark on the x2 axis with value ##x2(X)##
This is not what set link x2 will do. The second x-axis gets its own set of tics, so it will not mirror the position of the tics on the first x axis. To see this, try
Code:
set tics nomirror
set xrange[1:10]
set link x2 via 1/x inverse 1/x
set x2tics
plot x
 
@CAF123, what's happening with your other thread, the one about evaluating a function at numerous points? Your last (and only) post in that thread was almost five days ago.
 
DrClaude said:
This is not what set link x2 will do. The second x-axis gets its own set of tics, so it will not mirror the position of the tics on the first x axis. To see this, try
Code:
set tics nomirror
set xrange[1:10]
set link x2 via 1/x inverse 1/x
set x2tics
plot x
I see. Can you suggest a way for me to proceed with what I want to do?
 
Mark44 said:
@CAF123, what's happening with your other thread, the one about evaluating a function at numerous points? Your last (and only) post in that thread was almost five days ago.
I managed to come up with a solution outside of C++, i may come back to the thread later to discuss more.
 
Back
Top