Upper axis values through linking with lower axis gnu plot

  • Thread starter CAF123
  • Start date
  • Tags
    Axis Plot
In summary, 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 isx2 = 2*c**2/(2*x**2-c**2) with c=3.1The following should be sufficient
  • #1
CAF123
Gold Member
2,948
88
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
  • #3
@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?
 
  • #4
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
 
  • #5
@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.
 
  • #6
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?
 
  • #7
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.
 

FAQ: Upper axis values through linking with lower axis gnu plot

What is the purpose of linking upper axis values with lower axis in GNU plot?

The purpose of linking upper axis values with lower axis in GNU plot is to create a plot with two axes, where the upper axis values are directly related to the lower axis values. This allows for clearer visualization of the data and better understanding of the relationship between the two variables.

How do I link upper axis values with lower axis in GNU plot?

To link upper axis values with lower axis in GNU plot, you can use the set link command. This command allows you to specify the relationship between the two axes, such as linear or logarithmic, and the range of values for each axis. You can also use the set yrange and set xrange commands to manually set the range of values for each axis.

Can I have multiple linked upper and lower axes in a single GNU plot?

Yes, you can have multiple linked upper and lower axes in a single GNU plot. This can be useful when visualizing more complex data with multiple variables. You can use the set multiplot command to create multiple plots within the same figure, each with its own set of linked axes.

What types of data are best suited for linking upper and lower axes in GNU plot?

Linking upper and lower axes in GNU plot is best suited for data where there is a clear relationship between two variables, such as time series data or data with a known mathematical relationship. It can also be useful for comparing data from different sources or experiments.

Can I customize the appearance of the linked axes in GNU plot?

Yes, you can customize the appearance of the linked axes in GNU plot. You can use the set format command to change the format of the axis labels, such as adding a prefix or suffix. You can also use the set label command to add a title or label to each axis. Additionally, you can change the color, font, and size of the axes and labels using the set border and set label font commands.

Back
Top