amrith
amrith

Reputation: 973

Showing minor tic grid in gnuplot with manually defined major tics

I've been trying to graph the following data

1, 2050
2, 21246
3, 208557
6, 20971520
10, 306184192
12, 1.75922E+14

Using gnuplot, using the following ytics.

set ytics ( "1 kb" 1000, \
"10 kb" 10000, \
"100 kb" 100000, \
"1 mb" 1000000, \
"10 mb" 10000000, \
"100 mb" 100000000, \
"1 gb" 1000000000, \
"10 gb" 10000000000.0, \
"100 gb" 100000000000.0, \
"1 tb" 1000000000000.0, \
"10 tb" 10000000000000.0, \
"100 tb" 100000000000000.0, \
"1 pb" 1000000000000000.0, \
"10 pb" 10000000000000000.0 )

I can't get gnuplot to show the minor grid on this graph.

As I want the y axis to be logarithmic, it would be good to show the minor tics.

Between 1000 and 10000, I'd like minor tics every 1000. From 10000 to 100000, I'd like it to be 1e4 and so on.

How does one do this?

Upvotes: 2

Views: 5527

Answers (2)

theozh
theozh

Reputation: 26200

Maybe I completely misunderstood something, but why aren't you using the format specifiers %s %c? Check help format specifiers. These are available since "ever" (gnuplot 4.0 is the earliest version I checked).

By the way, the correct prefixes are M, G, T, P and not m, g, t, p. Maybe, is this the reason why you can't use gnuplot's and scientifically accepted prefixes?

Data: SO23047927.dat

1, 2050
2, 21246
3, 208557
6, 20971520
10, 306184192
12, 1.75922E+14

Script: tested with gnuplot4.0 (Apr 2004) and maybe works with even earlier versions

### set character replacement for scientific power
reset

set datafile separator ","

set yrange [1e3:1e16]
set logscale y
set ytics 10
set format y "%.0s %cB"
set grid y

plot "SO23047927.dat" u 1:2 w lp pt 7
### end of script

Result:

enter image description here

Upvotes: 0

Christoph
Christoph

Reputation: 48440

In order to understand the solution, there are some steps involved:

  1. Automatic major tics: All minor tics are drawn

    set yrange [1:100]
    set logscale y
    set mytics 10
    plot x
    

    enter image description here

  2. Manually set major tics: The minor tics aren't drawn

    set yrange [1:100]
    set logscale y
    set ytics ('one' 1, 'ten' 10, 'hundred' 100)
    set mytics 10
    plot x
    

    enter image description here

  3. Overwrite major tics with your own text (note the add): minor tics work!

    set yrange [1:100]
    set logscale y
    set ytics add ('one' 1, 'ten' 10, 'hundred' 100)
    set mytics 10
    plot x
    

    enter image description here

So, in your case it should be enough to use set ytics add ... and set mytics 10. You must also make sure, that you have a major tic every decade (set ytics 10), and also set the yrange manually for that many major tics:

set yrange [1e3:1e16]
set ytics 10
set mytics 10

set ytics add ( "1 kb" 1000, \
"10 kb" 10000, \
"100 kb" 100000,\
"1 mb" 1000000, \
"10 mb" 10000000,\
"100 mb" 100000000,\
"1 gb" 1000000000, \
"10 gb" 10000000000.0,\
"100 gb" 100000000000.0,\
"1 tb" 1000000000000.0, \
"10 tb" 10000000000000.0, \
"100 tb" 100000000000000.0, \
"1 pb" 1000000000000000.0, \
"10 pb" 10000000000000000.0 )

set logscale y
plot 'file.txt'

The result with 4.6.4 is:

enter image description here

Upvotes: 2

Related Questions