glvis icon indicating copy to clipboard operation
glvis copied to clipboard

Change colorbar number format

Open ddkn opened this issue 1 year ago • 4 comments

Hello,

Looking at the documentation I wasn't sure how to change the string format on the colorbar, or is this even possible? I would like it to be more consistent. Depending on the amount of significant figures you may get a float or scientific notation in the same colorbar.

image

It would be nice to have more control, such as show sign (+ and -) and control the significant figures after the decimal, e.g. +3.145e+00 and -3.145e+00. Again, I apologize if I have missed this option

Or is there a better way to export this for plotting?

Thanks in advance!

PS I believe glvis was installed through pip install glvis==0.3.3, which I think pulled in the latest binary 4.2

ddkn avatar Jun 30 '23 10:06 ddkn

There is unfortunately no way currently to control this at user level.

tzanio avatar Jun 30 '23 18:06 tzanio

Do you think it would be a desired feature? I may look into it trying to add it once I defend.

ddkn avatar Jul 01 '23 10:07 ddkn

Do you think it would be a desired feature? I may look into it trying to add it once I defend.

Definitely!

If you can build GLVis yourself, the change is not hard -- the corresponding code is in the following lines:

  • https://github.com/GLVis/glvis/blob/master/lib/vsdata.cpp#L500
  • https://github.com/GLVis/glvis/blob/master/lib/vsdata.cpp#L512

and maybe you want a diff like:

diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp
index 1934414..9e69eac 100644
--- a/lib/vsdata.cpp
+++ b/lib/vsdata.cpp
@@ -497,7 +497,7 @@ void VisualizationSceneScalarData::PrepareColorBar (double minval,
          val = ULogVal(i / 4.0);
 
          ostringstream buf;
-         buf << setprecision(4) << val;
+         buf << fixed << showpos << val;
          color_bar.addText(text_x,Y,posz, buf.str());
       }
    }
@@ -509,7 +509,7 @@ void VisualizationSceneScalarData::PrepareColorBar (double minval,
          Y = miny + (maxy - miny) * LogUVal(val);
 
          ostringstream buf;
-         buf << setprecision(4) << val;
+         buf << fixed << showpos << val;
          color_bar.addText(text_x,Y,posz, buf.str());
       }
    }

tzanio avatar Jul 02 '23 02:07 tzanio

@ddkn, were you able to resolve this?

tzanio avatar Aug 27 '23 18:08 tzanio