Mathplot - Plotting a vector data to both a primary and secondary y-axis

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Cittamatra
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Nov 16, 2018 8:36 pm

Mathplot - Plotting a vector data to both a primary and secondary y-axis

Post by Cittamatra » Thu Mar 19, 2020 2:13 pm

Hi all,

I've been using Mathplot for a while now, but have a couple of issues. Does anyone know how to write vector data to a secondary y-axis? I've created 4 layers to plot, picked up from 4 vectors. The code that I've used plots all vectors to just one y-axis. I'd like to split them up. Any help would be appreciated.

Here is the code I'm using:

Code: Select all

void MathPlotWnd::createMathPlot()
    {
        auto* const vectorLayer = m_plotData.getVectorLayer();
        auto* const vectorLayer2 = m_plotData.getVectorLayer2();
        auto* const vectorLayer3 = m_plotData.getVectorLayer3();
        auto* const vectorLayer4 = m_plotData.getVectorLayer4();

        wxPen vectorpen(*wxBLUE, 2, wxSOLID);
        wxPen vectorpen2(*wxGREEN, 2, wxSOLID);
        wxPen vectorpen3(*wxRED, 2, wxSOLID);
        wxPen vectorpen4(*wxLIGHT_GREY, 2, wxSOLID);

        vectorLayer->SetContinuity(true);
        vectorLayer->SetPen(vectorpen);
        vectorLayer->SetDrawOutsideMargins(false);
        vectorLayer2->SetContinuity(true);
        vectorLayer2->SetPen(vectorpen2);
        vectorLayer2->SetDrawOutsideMargins(false);
        vectorLayer3->SetContinuity(true);
        vectorLayer3->SetPen(vectorpen3);
        vectorLayer3->SetDrawOutsideMargins(false);
        vectorLayer4->SetContinuity(true);
        vectorLayer4->SetPen(vectorpen4);
        vectorLayer4->SetDrawOutsideMargins(false);

        wxFont graphFont(11, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);

        mpScaleX* xaxis = new mpScaleX(wxT("X"), mpALIGN_BOTTOM, true, mpX_NORMAL);
        mpScaleY* yaxis1 = new mpScaleY(wxT("Y1"), mpALIGN_LEFT, true);  		//Primary y-axis
        mpScaleY* yaxis2 = new mpScaleY(wxT("Y2"), mpALIGN_RIGHT, true); 	//Secondary y-axis

        xaxis->SetFont(graphFont);
        yaxis1->SetFont(graphFont);
        xaxis->SetDrawOutsideMargins(false);
        yaxis1->SetDrawOutsideMargins(false);

        MathPlot->SetMargins(20,20,20,20);
        MathPlot->AddLayer(xaxis);
        MathPlot->AddLayer(yaxis1);
        MathPlot->AddLayer(yaxis2);
        MathPlot->AddLayer(vectorLayer);
        MathPlot->AddLayer(vectorLayer2);
        MathPlot->AddLayer(vectorLayer3);
        MathPlot->AddLayer(vectorLayer4);
        MathPlot->AddLayer(new mpText(wxT("mpText sample"), 10, 10));
        
        wxBrush hatch(wxColour(200,200,200), wxSOLID);

        MathPlot->AddLayer( nfo = new mpInfoCoords(wxRect(80,20,10,10), wxTRANSPARENT_BRUSH));
        nfo->SetVisible(false);

        wxBrush hatch2(wxColour(163,208,212), wxSOLID);
        mpInfoLegend* leg;
        MathPlot->AddLayer( leg = new mpInfoLegend(wxRect(200,10,20,20), wxTRANSPARENT_BRUSH)); //&hatch2));
        leg->SetVisible(true);
        wxPen mypen(*wxRED, 5, wxSOLID);

        MathPlot->EnableDoubleBuffer(true);
        MathPlot->SetMPScrollbars(false);

}

 void MathPlotWnd::updateMathPlot()
    {
        m_plotData.getVectorLayer()->SetData(m_plotData.getTimeArray(), m_plotData.getArray1());
        MathPlot->Fit();

        m_plotData.getVectorLayer2()->SetData(m_plotData.getTimeArray(), m_plotData.getArray2());
        MathPlot->Fit();

        m_plotData.getVectorLayer3()->SetData(m_plotData.getTimeArray(), m_plotData.getArray3());
        MathPlot->Fit();

        m_plotData.getVectorLayer4()->SetData(m_plotData.getTimeArray(), m_plotData.gettArray4());
        MathPlot->Fit();
    }

Thanks,

Paul

Post Reply