Menu

#210 Same precision across all ticks on an axis

closed
nobody
None
5
2024-09-26
2016-12-02
No

Hi guys,

we are using Gnuplot in an interactive online system (http://giovanni.gsfc.nasa.gov/giovanni/) that can plot time series and scatter plot of various scientific climate data. Since the system supports all kinds of datasets, sometimes we are plotting values between 1 and 10, but sometimes - extremly large or extremly small numbers. Therefore, we are using:

set format y "%g"

This works nice most of the time. However, our science users insist that all ticks on a given axis should have the same number of significant numbers, which is not alway the case - e.g., see Y-axis on any plot on this page: http://www.phyast.pitt.edu/~zov1/gnuplot/html/statistics.html

We would like to have '0.0, 0.5, 1.0, 1.5, 2.0' instead of '0, 0.5, 1, 1.5, 2'

Is there a way to tell Gnuplot to not drop '0'? Ideally, we would like to avoid computing the proper format and precision ourselves, keeping plotting as much automatic as possible. Would massage the data help, e.g., in example ebove, try to plot 1.000001 instead of 1?

We are rocking Version 4.4 patchlevel 2, if that matters.

thanks,
Maksym

Discussion

  • Ethan Merritt

    Ethan Merritt - 2016-12-03
    1. That gnuplot version is really, really old.

    2. The format specifiers are standard C language formats. If you want to have specifically 1 digit after the decimal, the format should be "%.1f" or "%.1g"

     
  • Maksym Petrenko

    Maksym Petrenko - 2016-12-03

    Ethan, thank you for the reply. If we do specify "%.1g" , we will esentailly loose the native ability of Gnuplot/C++ to automatically estimate the number of significant digits. That is, currently, if we supply numbres like 1,2,3,4 - Gnuplot would display them as is. If we specify "%.1g", they will always be displayed as 1.0, 2.0, 3.0, 4.0. And if we want to be smart about it - we will have to esentially re-implement C++ logic for estimating the most suitable number of significant digits - something we would love to avoid doing. Therefore, my question is more along the lines - does Gnuplot have a built-in feature that basically would it for us?

    As for the version - we are limited to what's available in the officail RPM repository of CentOS 6. Would the newer Gnuplot have a feature like that?

    Thanks for your help!

     
  • Ethan Merritt

    Ethan Merritt - 2016-12-03

    I don't know what "C++ logic" you are referring to. So far as I know, C++ uses the same format specifiers as C. See for instance http://www.cplusplus.com/reference/cstdio/printf/, which looks identical to C. Can you point me to documentation of the feature you want?

    As to the version - asking about "the" newer gnuplot misses the mark. Your version 4.4.2 is so old that multiple development series have come and gone in the interim. You are apparently missing out on ~10 years of program development throughout the version 4.4, 4.6 and 5.0 release series. The current release version is 5.0.6. Anyhow, yes version 5 of gnuplot is smarter about the number of decimal points used for axis labels and offers format options that didn't exist in 4.4, but they may not match exactly what you are looking for.

     
  • Maksym Petrenko

    Maksym Petrenko - 2016-12-03

    Sorry, yes, I meant C logic, wich indeed is pretty much identical to C++ (I'm by no means an expert on either). I will look more into standards and maybe source code in gcc, but I don't think they will lead me anywhere - essentially, I'm trying to dynamically compute a format precision based on a series of numbers (i.e., based on all ticks on a given axis).

    Looks like the simple answer is no, Gnuplot does not have a built-in option like that. My second question - is there a way to access tick values computed by Gnuplot (something like set xticks, but only get xticks)? If I had an access to the computed ticks, I could analyze them to find the longest tick and use its precision as a specifier for %g. I guess I can also get some approximation by directly sprintf'ing my min and max numbers in my script before building a gnuplot script.

    I will also try the latest version of Gnuplot to see if it does any better in this specific problem.

     
  • Ethan Merritt

    Ethan Merritt - 2024-09-26
    • Status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB