3

Is there a way to make the format of x/y tic-labels of a graph dependent on the value of the tic? I'm envisioning a statement of the format

set format y ( ( ( <arg> > 1e-3 ) && ( <arg> < 1e2 ) ) ?  "%2.1f" : "10^{%T}" )

so that a log scale graph would be represented as

10^{-4}, 10^{-3}, 0.01, 0.1, 1, 10, 10^{2}

and so on, to give a more natural representation for numbers near 1.

I know this can be done by explicitly declaring the format, i.e.,

set xtics ( "10^{-3}" 1e-3, "0.01" 0.01, "0.1" 0.1, "1" 1, "10" 10, "10^{2)" 1e2 )

but I'd like to avoid being so specific, since this set of labels changes every time the range of the graph changes. I expect the answer to this question is 'no', but here's hoping.

1 Answer 1

5

Well...That depends on how hard you want to have to work to make this plot. Here's an example which does what you want. It's a somewhat difficult plot to make in an automated fashion, (You need to adjust the margins for titles, etc) but if you just need a good looking plot for a presentation or paper and have time to spend making it look how you want, this should work OK.

set termoption enhanced

#for this to work, we need to set ranges explicitly :-(
set xrange [-10:10]
set yrange [1e-4:exp(10)]

#Yippee!!! logscale plots :-)
set logscale y

#We'll make 3 plots.  The first plot is of the data and a piece of the y range tics
# the next two plots have no data, they only add another piece of the range tics.
set multiplot

#for this to work, we have to guarantee that all the plots line up exactly
set lmargin at screen 0.1
set bmargin at screen 0.1
set rmargin at screen 0.9
set tmargin at screen 0.9

set ytics 1e-2,10,90 format "%g"  #center of the range, normal tics.
plot exp(x)+exp(-x)               #looks like a V in logscale.  Neat.
unset xtics                       #already did this once.  don't need to put it on again.
unset border                      #already did this once too...
set ytics 100,10 format "10^{%L}" #Next plot, top end of the tics
plot NaN notitle                  #plots nothing.  Only works if range is set explicitly.
set ytics 1e-5,10,9e-3            #next plot, low end of the tics

#Any additional labels, objects, arrows, the title etc. should go here.  
#Otherwise you'll need to unset them like we did with the xtics and border 
#to prevent them from being plotted twice 
#(objects which are plotted twice sometimes look a little bit darker than they should).

plot NaN notitle
unset multiplot                   #and we're done.
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. That's somewhat convoluted, but it avoids re-specifying the tic labels manually, which is what I was going for. Thanks! (I'd upvote, but I don't have enough reputation yet.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.