Page 1 of 1

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

Posted: Thu Mar 19, 2020 2:13 pm
by Cittamatra
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. I added a second mpScaleY, but the scale appears identical to the primary y-axis.

An image of the plot is shown here:
Mathplot dual axis 3.jpg
Mathplot dual axis 3.jpg (13.56 KiB) Viewed 13264 times

I can't find a way to add an array to 'yaxis2'. It just creates yaxis2 as a duplicate of yaxis1. There doesn't seem to be a command that differentiates between, 'plot array to yaxis1 or yaxis2'. See attached for an image of the plot.

Here is the code I've written:

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();
    }

mpScaleY create the two scales, aligned left and right. 'SetData' adds the arrays to the plot.


Any help would be much appreciated.

Thanks,

Paul