GLVis / glvis

Lightweight OpenGL tool for accurate and flexible finite element visualization
http://glvis.org
BSD 3-Clause "New" or "Revised" License
249 stars 51 forks source link

Change colorbar number format #260

Closed ddkn closed 1 month ago

ddkn commented 1 year ago

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

tzanio commented 1 year ago

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

ddkn commented 1 year ago

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

tzanio commented 1 year ago

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:

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 commented 1 year ago

@ddkn, were you able to resolve this?

tzanio commented 1 month ago

Discussion continued in #288