3

Using the QCustomPlot add on for QT. I am having to plot points which may are not linear so the graph could look something like this enter image description here

how ever this is the result

enter image description here

but this is what shows up

using this code

    plotter->addGraph();
    plotter->graph(0)->setData(xVector, yVector);
    plotter->xAxis->setLabel("X");
    plotter->yAxis->setLabel("Y");
    plotter->xAxis->setRange(x_data_range_min x_data_range_max);
    plotter->yAxis->setRange(y_data_range_min, y_data_range_max);
    plotter->replot();
    plotter->saveJpg("test.jpg");
    plotter->close();

now I found a partial fix, by adding this option to get ride of the connected lines and only show the points,

    plotter->graph(0)->setLineStyle((QCPGraph::LineStyle)QCPGraph::lsNone);
    plotter->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc , 3));

and the result is this but has a problem, it leaves a kinda bold spot which I can't have

enter image description here

so this is a semi-solution. So I went ahead and added what A. Sarid mentioned in the replys below. I think the first graph may plot fine, but any other graph after it looks like this

enter image description here

so I am not sure which solution can make only the dots connect in the order in which they are received from the array

Tanner Summers
  • 689
  • 1
  • 8
  • 26

1 Answers1

3

I just had the same problem few days ago. You need to use QCPCurve Class instead of Graph. Here is a small example of how to do it:

this->newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
ui->customPlot->addPlottable(this->newCurve);

And then you can use it the same way you use graph, for example:

this->newCurve->setData(x, y);
A. Sarid
  • 3,916
  • 2
  • 31
  • 56
  • not working, the data is coming out very odd, it its adding so many extra lines and looks like it is also producing double values, not sure why – Tanner Summers Apr 21 '16 at 20:29
  • @Tanner it will be helpful if you'll add relevant parts from your code and give some background of what you are trying to plot. – A. Sarid Apr 21 '16 at 20:32
  • I know sorry I was about to edit my comment, ok so my program reads in multiple files and plots them. Doing what you said to do, I am not sure if its plotting points from previous graphs since it should not since the data gets reset per method call, this is also how i been doing it with the qcustomplot object alone. anyways doing what you said, the everything after the first graph looks like this http://imgur.com/NUGEMq6 and i am trying to draw something like this http://imgur.com/6FAbv7L based off the points, i will update original post right now – Tanner Summers Apr 21 '16 at 20:38
  • make sure that the data in your x, y vectors are first of all syncronized and second, in the right order you want them to be. QCPCurve uses another coordinate _t_ which defines the order of the points, maybe the order you insert the data to the plot is not really the order you want it to be. – A. Sarid Apr 21 '16 at 21:03
  • the order should be fine, the data given to me is out of my control, it is the order in which someone is drawing the lines, as for the t value, not sure how to use it, but i can look up the documentation and try to figure it out – Tanner Summers Apr 21 '16 at 21:11
  • 1
    I think I got it, i had to use the curve like you said, but every loop for each graph I had to clear the curve. :) thank you A Sarid – Tanner Summers Apr 22 '16 at 06:44