Search code examples
gnuplotopentsdb

gnuplot y-axis format convert bytes to megabytes


Using OpenTSDB we are capturing the number of bytes sent over the network interface per second. When graphing these figures the Y axis has scientific notation (i.e. 5e+07). The help text for the y-axis format option suggests that it can be used to convert bytes to megabytes or gigabytes - and refers to the Format Specifiers section of the GNU Plot documentation. I've read that but its still not clear to me how to convert the values. I could not find any examples where people had done the conversation by setting the Y axis format.


Solution

  • The format specifier %c gives you the character replacement of the respective scientific power, e.g. k for 1e3, M for 1e6 etc. The specifier %s sets the corresponding mantissa.

    Consider the following file test.dat:

    1e7
    2e7
    5e7
    1e8
    

    With the script

    set format y '%.0s%cB'
    plot 'test.dat' with linespoints
    

    you get the output (using 4.6.5):

    enter image description here