Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to draw a reciprocal axis in gnuplot

1,910 views
Skip to first unread message

erkin

unread,
Jun 12, 2010, 12:45:43 PM6/12/10
to

hi,

I am a beginner for gnuplot, I will appreciate if somebody can give me
hint for how to draw a reciprocal axis.

thanks in advance
Erkin

dai_bach

unread,
Jun 13, 2010, 4:59:51 AM6/13/10
to
What do you mean by a reciprocal axis? Do you want to define a new
range (say x') for the function which is (x->1/x'), change the labels
on the axis to be the inverse of the value of the function, or maybe
use a secondary axis?

Karl

unread,
Jun 13, 2010, 6:54:13 AM6/13/10
to
perhaps this is what you´re thinking of?

set parametric
set trange [0.1:25]
plot 1/t, f(t)

karl

Karl

unread,
Jun 13, 2010, 10:49:09 AM6/13/10
to
Karl schrieb:
> plot 1/t, f(t)

gp> plot 1/t, f(1/t)

,of course.

erkin

unread,
Jun 13, 2010, 11:07:09 AM6/13/10
to


hi,

thanks for the reply. it seems I have to explain my problem more
detailed.

I want to draw a plot of light intensity v.s. photon energy (E). I set
the X axis range as [E1,E2], I also want to show the corresponding
wave length of the light (lambda) in the secondary axis X2. because of
he relationship between the E and lambda is: lambda(nm)=1240/E(eV),
the range of X2 should be [lambda1, lambda2]. Please note that
lambda1>lambda2, but it can be done by reverse mode. But the problem
is the step in the X2 is not linear, it is reciprocal of the X axis.
So it should looks like a logarithmic scale, especially when the range
is big. How should I set X2?

I hope I explained my question clearly. It can be done in Origin very
easily, but I didn't find any help on all gnuplot manuals I can find.

thanks
Erkin

erkin

unread,
Jun 13, 2010, 11:29:34 AM6/13/10
to

it seems I can't put any attachment to this site, so I put a sample of
reciprocal axis to here: http://users.tkk.fi/~aierken/files/Graph2.jpg
I draw it on Origin, can we do it in gnuplot?

thanks
Erkin

Karl

unread,
Jun 13, 2010, 1:07:33 PM6/13/10
to

you have to set identically ranges on both x and x2

gp> set xrange [0.85:1.55]
gp> set x2range [0.85:1.55]

and place the tics manually

gp> set xtics nomirror
gp> set x2tics "1450"1240/1450.0, \
"1250"1240/1250.0, \
"1050"1240/1050.0, \
"850"1240/850.0)

to where you want them. The axes are totally independant, so you´ve got
to be very careful! ;-)

erkin schrieb:

Hans-Bernhard Bröker

unread,
Jun 13, 2010, 1:12:12 PM6/13/10
to
erkin wrote:

> I want to draw a plot of light intensity v.s. photon energy (E). I set
> the X axis range as [E1,E2], I also want to show the corresponding
> wave length of the light (lambda) in the secondary axis X2.

That fails for two reasons

1) gnuplot doesn't do generic axis scaling (only linear or logarithmic)
2) gnuplot doesn't do coupling of one axis to values to the other (like
the relation between E and lambda)

The closest approximation would be to make both x and x2 axis
logarithmic (to make the relation between graph positions a linear one),
then fix both ranges explicitly:

f_lambda(E) = 1240/E
set log x
set log x2
set xrange [E1:E2]
set x2range [f_lambda(E1) : f_lambda(E2)]

If for some reason logarithmic axes can't be used, you'll have to
do your x2 axis manually, using the long form of the 'set x2tics' command:

set x2range [1:10]
set x2tics (1 '100', 2 '50', 4 '25', 10 '10')

erkin

unread,
Jun 13, 2010, 1:34:10 PM6/13/10
to

thanks for your answers Karl and Hans-Bernhard. now I got it.

one more question, just come to my mind.
can I do ln (e based logarithmic) and lg (2 based logarithmic) axis?

thanks
Erkin

Hans-Bernhard Bröker

unread,
Jun 13, 2010, 1:57:38 PM6/13/10
to
erkin wrote:

> one more question, just come to my mind.
> can I do ln (e based logarithmic) and lg (2 based logarithmic) axis?

Read "help set log" for yourself.

sfeam

unread,
Jun 13, 2010, 5:15:49 PM6/13/10
to
erkin wrote:

I have a web site that generates plots exactly as you want,
with energy on x1 and wavelength on x2
http://skuld.bmsc.washington.edu/scatter/AS_form.html

So yes, it is possible. But the intelligence lies in the script that
generates gnuplot output, not in gnuplot itself. Note that in the
scripts generated by the link above, the gnuplot axes are both mouseable,
even though one is a reciprocal axis.

krutok...@gmail.com

unread,
Jun 25, 2013, 8:49:24 AM6/25/13
to
On Sunday, June 13, 2010 11:15:49 PM UTC+2, sfeam wrote:

> So yes, it is possible.
There is no scaled minor tics for the X2 axis. Is there any chance to put that way ?

So far I failed to do so by "set x2tics scale 1.0... " and set x2tics scale 0.5 add "

Werner

unread,
Mar 5, 2015, 4:48:39 PM3/5/15
to
One trick I use is, overlay two graphs in multiplot. The second graph with 1 / lambda is generated as follows: plot [3.5: 1.0] 'A_B_C_D.dat' u (1239.84187 / $ 1) ($5)

Ethan A Merritt

unread,
Mar 5, 2015, 6:22:43 PM3/5/15
to
This is now supported directly in gnuplot 5
See
http://gnuplot.sourceforge.net/demo_cvs/linkedaxes.html
0 new messages