Hi all,

I am a newbie in QWT. Just wish to ask how can I plot data from a vector. The code below shows what I have done so far. Basically, the data I am storing into the vector are pixel values of an image along the axis. After that, I proceed to plot them, but there is always an error. I am not sure how to exactly do them either:/ I been trying to plot for almost 2 weeks plus already. But to no avail. I am still confused over the curve as well, why is there another vector needed for the setSamples() of curve?

Qt Code:
  1. vector<byte> v_char; //values of pixels taken from y-axis //tried double and int as well.
  2.  
  3. //store pixel values into v_char
  4. v_char.reserve(image.rows * image.cols);
  5.  
  6. for (int i = 0; i < image.rows; i++)
  7. {
  8. int segment_start = *(uchar*)image.data + i * image.step;
  9. v_char.insert(v_char.end(), segment_start, segment_start + image.cols);
  10. }
  11.  
  12. //plotting of v_char vector
  13. QwtPlot *plota=new QwtPlot(); //Create plot widget
  14. plota->setTitle( "Plot Analysis" ); //Name the plot
  15. plota->setCanvasBackground( Qt::black ); //Set the Background colour
  16. plota->setAxisScale( QwtPlot::yLeft, 0, 1000000 ); //Scale the y-axis
  17. plota->setAxisScale(QwtPlot::xBottom,0,image.rows); //Scale the x-axis
  18. plota->insertLegend(new QwtLegend()); //Insert a legend
  19.  
  20. //attach curve to plota
  21. QwtPlotCurve *curvea = new QwtPlotCurve(); // Create a curve
  22. // curvea->setTitle("Count"); //Name the curve
  23. curvea->setPen( Qt::white, 2);//Set colour and thickness for drawing the curve
  24. //Use Antialiasing to improve plot render quality
  25. curvea->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  26.  
  27. QPolygonF points;
  28. for( int h = 0; h < v_char.size(); ++h)
  29. {
  30. float bin_value = v_char[h];
  31. points << QPointF((float)h, bin_value);
  32. }
  33. curvea->setSamples(points); //pass points to be drawn on the curve
  34. curvea->attach( plota ); // Attach curve to the plot
  35.  
  36. plota->resize( 600, 400 ); //Resize the plot
  37. //plot.replot();
  38. plota->show(); //Show plot
To copy to clipboard, switch view to plain text mode 

If anybody do know, please please do help, I already at my wits end. I can't seem to find an example or tutorial online for QWT plots. I already tried lots of things... Is there a problem with my code? Or my whole programming flow is wrong? Please help. Thanks.