-
|
As the title suggests, is there a way to programmatically autofit data? Adding data to the plot after the fact doesn't fit automatically and the user has to autofit to see the new data. If there was a way to autofit the data, I could just call it, when adding new data. I tried using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
How I've done it for now: if (triggerAutofit) {
triggerAutofit = false;
ImPlot3DContext& gp = *ImPlot3D::GImPlot3D;
ImPlot3DPlot& plot = *gp.CurrentPlot;
plot.FitThisFrame = true;
for (int i = 0; i < 3; ++i) {
plot.Axes[i].FitThisFrame = true;
}
}
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @Poooel, the flag if (triggerAutofit) {
ImPlot3D::SetupAxes(nullptr, nullptr, nullptr, ImPlot3DAxisFlags_AutoFit, ImPlot3DAxisFlags_AutoFit, ImPlot3DAxisFlags_AutoFit);
}I modified the static float xs1[1001], ys1[1001], zs1[1001];
for (int i = 0; i < 1001; i++) {
xs1[i] = i * 0.001f;
ys1[i] = 0.5f + 0.5f * cosf(50 * (xs1[i] + (float)ImGui::GetTime() / 10));
zs1[i] = 0.5f + 0.5f * sinf(50 * (xs1[i] + (float)ImGui::GetTime() / 10));
}
static double xs2[20], ys2[20], zs2[20];
for (int i = 0; i < 20; i++) {
xs2[i] = i * 1 / 19.0f;
ys2[i] = xs2[i] * xs2[i];
zs2[i] = xs2[i] * ys2[i];
}
// Button to trigger auto-fit
bool trigger_auto_fit = false;
if (ImGui::Button("Trigger auto-fit"))
trigger_auto_fit = true;
if (ImPlot3D::BeginPlot("Line Plots")) {
// Use AutoFit flag when needed
ImPlot3DAxisFlags flags = trigger_auto_fit ? ImPlot3DAxisFlags_AutoFit : ImPlot3DAxisFlags_None;
ImPlot3D::SetupAxes("x", "y", "z", flags, flags, flags);
ImPlot3D::PlotLine("f(x)", xs1, ys1, zs1, 1001);
ImPlot3D::SetNextMarkerStyle(ImPlot3DMarker_Circle);
ImPlot3D::PlotLine("g(x)", xs2, ys2, zs2, 20, ImPlot3DLineFlags_Segments);
ImPlot3D::EndPlot();
}Peek.2024-12-27.16-26.mp4Do let me know if this works for you! |
Beta Was this translation helpful? Give feedback.
Hi @Poooel, the flag
ImPlot3DCond_Oncecurrently only works with theSetupAxisLimitsmethod. When used, it will set the limits only the first time the plot is created (first call toSetupAxisLimitsfor that plot). If you have new data coming in and you want it to be fitted, you could callSetupAxis/SetupAxeswith the flagImPlot3DAxisFlags_AutoFitto fit the data in that frame.I modified the
Line Plotsdemo to test this and it appears to work fine