openGLPlotLive icon indicating copy to clipboard operation
openGLPlotLive copied to clipboard

Scatter plot

Open wfphys opened this issue 1 year ago • 0 comments

Hi, I would like to know if it is possibile to update dynamically a graph containing scatter plots. For example, by using lines, this code works:

// Init GLFW
std::shared_ptr<GLPL::IWindow> window = std::shared_ptr<GLPL::IWindow>(new GLPL::Window(windowWidth, windowHeight,  false, false));
std::shared_ptr<GLPL::Window> window2 = std::dynamic_pointer_cast<GLPL::Window>(window);

std::shared_ptr<GLPL::Plot> myplot = std::make_shared<GLPL::Plot>(0.0, 0.0, 1.0, 1.0, window2->getParentDimensions(), 2, 2);
std::shared_ptr<GLPL::IDrawable> myPlotPt = std::dynamic_pointer_cast<GLPL::IDrawable>(myplot);
window2->addPlot(myPlotPt);

std::shared_ptr<GLPL::Axes2D> axesPt = std::dynamic_pointer_cast<GLPL::Axes2D>(myplot->getAxes(0));

std::shared_ptr<GLPL::ILine2D> line9s = axesPt->addLine(&xVec57, &yVec57, GLPL::SINGLE_LINE, LC_MAGENTA, 1.9, "Theor Flow");
std::shared_ptr<GLPL::Line2D2Vecs> line9sd = std::dynamic_pointer_cast<GLPL::Line2D2Vecs>(line9s);

/*float i = 0;*/
while(!glfwWindowShouldClose(window->getWindow())) {

    window2->preLoopDraw(true);


    line9sd->dataPtX->clear();
    line9sd->dataPtY->clear();

    line9sd->dataPtX->push_back(modeN);
    line9sd->dataPtY->push_back(0);
    line9sd->dataPtX->push_back(modeN);
    line9sd->dataPtY->push_back(matInput[modeN][2]);
    ....
    line9sd->updateInternalData();

    // Draw Plot
    myplot->Draw();

    // Post-loop draw
    window2->postLoopDraw();
}

First question: is this the way of proceeding correct, in order to update the vector at each step in the loop? Second question: for scatter plot, a method 'updateInternalData' does not exist. I there way to update a scatter plot dynamically?

Thank you Walter

wfphys avatar Apr 26 '24 10:04 wfphys