Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis Labels near Zero in Colormap #176

Closed
jvannugteren opened this issue Feb 8, 2021 · 7 comments
Closed

Axis Labels near Zero in Colormap #176

jvannugteren opened this issue Feb 8, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@jvannugteren
Copy link

First of all thank you very much for sharing this great library. It has been very useful for my project, which involves magnetic field calculation for coils and permanent magnets.

While using the heatmap I found a graphical bug in the color scale that sometimes appears but not always. The axis label near zero sometimes goes to scientific notation, failing to just round to 0.0. I'm using the master branch of your repository. I have attached a screenshot to illustrate the issue.

image

@epezent
Copy link
Owner

epezent commented Feb 26, 2021

@jvannugteren , would you mind producing a minimal example of this so I can debug the issue?

@epezent epezent added the bug Something isn't working label Feb 26, 2021
@jvannugteren
Copy link
Author

Thanks for having a look.

I made a minimalistic example case. See code below.

const float lim1 = -0.14;
const float lim2 = 0.14;
const float height = 400;
ImGui::SetNextWindowSize(ImVec2(600,500), ImGuiCond_Once);
if(ImGui::Begin("myid")){
    if(ImPlot::BeginPlot("blaat","x-axis","y-axis",{ImGui::GetWindowWidth()-100,height})){
        // it doesn't matter what you plot
        ImPlot::EndPlot();
    }
    ImGui::SameLine();
    ImPlot::ShowColormapScale(lim1, lim2, height);
}
ImGui::End();

This gives me the following result:
image

When lim1 and lim2 (in the example) are for example minus and plus 1.4, the colorscale is shown correctly. Therefore I suspect some sort of rounding error. Or fail to detect zero due to numerical precision.

@epezent
Copy link
Owner

epezent commented Feb 26, 2021

Thanks. I'll give this a look soon!

@epezent
Copy link
Owner

epezent commented Mar 3, 2021

@jvannugteren, can you let me know if this commit b958abf resolves your issues?

@jvannugteren
Copy link
Author

Unfortunately not completely. The example with limits -0.14 to 0.14 is now fine.

However, the following example still produces the problem:

// lock next window position
const float lim1 = -1.24;
const float lim2 = 0.45;
const float height = 400;
ImGui::SetNextWindowSize(ImVec2(600,500), ImGuiCond_Once);
if(ImGui::Begin("myid")){
    if(ImPlot::BeginPlot("blaat","x-axis","y-axis",{ImGui::GetWindowWidth()-100,height})) {
        ImPlot::EndPlot();
    }
    ImGui::SameLine();
    ImPlot::ShowColormapScale(lim1, lim2, height);
}
ImGui::End();

image

@epezent
Copy link
Owner

epezent commented Mar 7, 2021

I just pushed another fix that should resolve the issue. In addition, I took another look at this function and added a few improvements. Namely, the signature has change to accept an ImVec2 size instead of just the height. Leave the x value at 0 for the previous auto-sizing policy, or set it to a desired value for a fixed width widget.

46ea9ab

If this resolves your issue, feel free to close. Thanks!

@jvannugteren
Copy link
Author

This seems to solve the problem. Thanks again for the fix and great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants