I created the following function to make the value Y just be showed when is not 0(zero). So I set $plot->SetYLabelType('custom', 'labelYSemZero');.
function labelYSemZero($label) { if ($label == 0) return ''; return number_format($label,2,',','.'); }
Is it useful to show the value zero? Maybe it could have a flag or something like that to show or not value zero.
(Better late than never, maybe? Sorry.)
When this was opened, it seemed to me that the existing custom label formatting function was an acceptable solution. And I don't like adding narrowly targetted features (like "suppress zero in labels").
But recently I got an idea from spreadsheets, which have cell formatting (and a TEXT() function) that accept 1, 2, or 3 separate format controls, which are applied depending on the sign of the value. I tried something similar in PHPlot, by extending the 'printf' label format to accept 1, 2, or 3 formats.
With 1 format, it works as before: formats all labels with that format.
With 2 formats F1 and F2, it uses F1 for values >= 0, and F2 for values < 0.
With 3 formats F1, F2, and F3, it uses F1 for values > 0, F2 for values < 0, and F3 for values that are 0.
Your case then becomes something like this: $plot->SetYLabelType('printf', '%f', '-%f', '');
Note the minus sign is needed because the second format is applied to the absolute value. This lets you do things like '(%f)' to show negative values in parenthesis, as in some financial documents.
Yes this is a little more complex than a new method "SuppressZeros(True)", but is much more flexible.
Last edit: lbayuk 2015-10-29
Code changes, new test scripts, and documentation updates have been committed to SVN. This will be in the next release, 6.2.0.
Implemented in 6.2.0