Plot raw data Points with wxPlotCtrl Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Plot raw data Points with wxPlotCtrl

Post by orbitcowboy »

Hi @all,

is it possible to draw a set of raw data points with wxPlotCtrl?
I 've just found the wxPlotCtrl::AddCurve(...) function , drawing an interpolated function of the given datapoints. In my Application i want to draw a set of points.... can anybody help me?

Regards

Orbitcowboy
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg »

you need to create a wxPlotData and add that.

wxPlotData is for plotting points.
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

thanks for your answer but,

m_PlotCtrl = new wxPlotCtrl(this,wxID_ANY);

wxPlotData *m_PlotData = new wxPlotData(1000,true);

for(int iIndex = 0; iIndex < 1000; iIndex ++)
{
m_PlotData->SetXValue(iIndex,cos(static_cast<double>(iIndex)));
m_PlotData->SetYValue(iIndex,-sin(static_cast<double>(iIndex)));

}
if(m_PlotData->Ok())
{ m_PlotCtrl->AddCurve(m_PlotData, true, true);}

by plotting this points, the genereted points are interpreted as a function. Question: Is it possible to draw just the raw points (without interpolation)?

I need this in my application, because i intend to display a matrix with data points, simply like this:
e.g:
y
^
| 0 0 0 1 0 0 1 0 0 0
| 1 0 0 1 0 0 1 0 1 0
| 0 0 0 1 0 0 1 0 0 0
| 0 0 0 1 0 0 1 0 1 0
| 1 0 0 1 0 0 1 0 0 0
--------------------->x

all the values '1' whould be drawn as point.

Regards

Orbitcowby
fantaz
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Mon Sep 13, 2004 10:07 am
Location: Croatia

Post by fantaz »

In plotctrl.h:

Code: Select all

 ...
// Draw the data curve symbols on the plotctrl
    bool GetDrawSymbols() const { return m_draw_symbols; }
    void SetDrawSymbols( bool drawsymbols = true )
        { m_draw_symbols = drawsymbols; Redraw(wxPLOTCTRL_REDRAW_PLOT); }

    // Draw the interconnecting straight lines between data points
    bool GetDrawLines() const { return m_draw_lines; }
    void SetDrawLines( bool drawlines = true )
        { m_draw_lines = drawlines; 
Redraw(wxPLOTCTRL_REDRAW_PLOT); }
...
So, you'd have to do something like this:

Code: Select all

m_plotCtrl->SetDrawLines(false);
m_plotCtrl->SetDrawSymbols(true);
hope this helps a bit
best regards,
fantaz
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

Great!Thanks for your help!

Orbitcowboy
Agucho
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sat Jul 09, 2011 8:20 pm

Re: Plot raw data Points with wxPlotCtrl

Post by Agucho »

I cant draw raw points! the code im trying is:

Code: Select all

Grafica1->DeleteCurve(-1,false);
    Grafica1->SetDrawLines(false);
    Grafica1->SetDrawSymbols(true);
    Grafica1->SetZoom(0,0,1,1,false);

    int x1=5,x2=7;
    int y1=6,y2=4;
    int range=2;
    wxPlotData *data_dir=new wxPlotData(range,false);
    data_dir->SetValue(0,x1,y1);
    data_dir->SetValue(1,x2,y2);
    wxGenericPen pen(wxGenericColour(220, 20, 60));
    data_dir->SetPen(wxPLOTPEN_NORMAL, pen);
    Grafica1->AddCurve((const wxPlotData&)*data_dir,false,false);
   
    Grafica1->Redraw(wxPLOTCTRL_REDRAW_PLOT);
Grafica1 is my wxPlotCtrl.

Please explain me how to draw raw points because with this code I only hace a diagonal line, and if i only try to draw a single point i also have a line between the point i define and the origin.
Thanks!
Post Reply