Results 1 to 11 of 11

Thread: Strange extra line in my plotting, help please

  1. #1
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Strange extra line in my plotting, help please

    Hi everyone,

    I am new to the Qwt. I need to plot a curve against time. Here is my code:

    Qt Code:
    1. int plotSize = 100;
    2. int timeCnt = 0;
    3.  
    4. void cycleScrDialog::setPlot()
    5. {
    6. // create a plot
    7. QwtPlot *cyclePlot;
    8. QwtText title("cyclePlot");
    9. cyclePlot = new QwtPlot(title);
    10.  
    11. // add curves
    12. QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
    13. curveT->setPen(QPen(Qt::red,1));
    14. curveT->attach(ui->qwtPlot);
    15. QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
    16. curveP->setPen(QPen(Qt::blue,1));
    17. curveP->attach(ui->qwtPlot);
    18.  
    19. // add Axis
    20. ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100);
    21. ui->qwtPlot->setAxisFont(QwtPlot::xBottom, QFont(QString("Sans Serif"), 5, 0, false));
    22. ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -1, 1);
    23. ui->qwtPlot->setAxisFont(QwtPlot::yLeft, QFont(QString("Sans Serif"), 5, 0, false));
    24.  
    25. // initialize plot data
    26. for (int i = 0; i < plotSize; i ++)
    27. {
    28. x[i] = 0;
    29. yT[i] = 0;
    30. yP[i] = 0;
    31. }
    32.  
    33. curveT->setRawData(x,yT,plotSize);
    34. curveP->setRawData(x,yP,plotSize);
    35. }
    36.  
    37. void cycleScrDialog::timerEvent() // timer generates event every 1/4 second
    38. {
    39. if (timeCnt < plotSize)
    40. {
    41. x[timeCnt] = timeCnt;
    42. yT[timeCnt] = sin(timeCnt * 0.25);
    43. yP[timeCnt] = cos(timeCnt * 0.5);
    44. ui->qwtPlot->replot();
    45. timeCnt ++;
    46. }
    47. else
    48. timeCnt = 0;
    49. }
    To copy to clipboard, switch view to plain text mode 

    I have two questions here:
    1. when i run the program, it is plotting a straight line between the (0,0) and new plot dot coordinate.


    I have read through this forum. but i didn't anyone get the same problem.

    2. I can resize the axis font. However, I can't find a way to resize the axis itself (in green area). I wonder the axis size is fixed, and cannot be changed. Am I right?



    Can anyone give me a hint, please?
    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,316
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange extra line in my plotting, help please

    1) Obviously there is a (0, 0) at the end of your data left from the initialization
    2) plotLayout()->setAlignCanvasToScales(true);

    Uwe

  3. #3
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    Hi Uwe,

    Thanks for your kind reply.

    1) You can see I want to plot temperature and pressure data against time. I have tried different code. But I either got curve1 or curve2

    curve 1


    curve 2

    the code for curve1:

    Qt Code:
    1. int plotSize = 100;
    2. int timeCnt = 0;
    3.  
    4. // initialize plot data
    5. for (int i = 0; i < plotSize; i ++)
    6. {
    7. x[i] = 0;
    8. yT[i] = 0;
    9. yP[i] = 0;
    10. }
    11. curveT->setRawData(x,yT,plotSize);
    12. curveP->setRawData(x,yP,plotSize);
    13.  
    14. void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
    15. {
    16. timeCnt ++;
    17. if (timeCnt % 4 == 0)
    18. {
    19. x[chartCnt] = chartCnt;
    20. yT[chartCnt] = 0.9;
    21. yP[chartCnt] = -0.5;
    22. ui->qwtPlot->replot();
    23. if (chartCnt < plotSize)
    24. chartCnt ++;
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    code for curve 2

    Qt Code:
    1. int plotSize = 100;
    2. int timeCnt = 0;
    3.  
    4. // initialize plot data
    5. for (int i = 0; i < plotSize; i ++)
    6. {
    7. x[i] = i; // here is the only difference
    8. yT[i] = 0;
    9. yP[i] = 0;
    10. }
    11. curveT->setRawData(x,yT,plotSize);
    12. curveP->setRawData(x,yP,plotSize);
    13.  
    14. void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
    15. {
    16. timeCnt ++;
    17. if (timeCnt % 4 == 0)
    18. {
    19. x[chartCnt] = chartCnt;
    20. yT[chartCnt] = 0.9;
    21. yP[chartCnt] = -0.5;
    22. ui->qwtPlot->replot();
    23. if (chartCnt < plotSize)
    24. chartCnt ++;
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    it looks like it always links to next data (initialized data) when it plotting the last data. Can do I get rid of last plotting data, then it will look like:


    2) to resize the scale, i changed my code as follow. However, no matter how do I changed the “int margin” value, I didn't see any changed of the scale. Could you please give me some advice about my code?

    Qt Code:
    1. void cycleScrDialog::setPlot()
    2. {
    3. // create plot
    4. QwtPlot *cyclePlot;
    5. QwtText title("cyclePlot");
    6. cyclePlot = new QwtPlot(title);
    7.  
    8. // resize scale
    9. layout->setAlignCanvasToScales(false);
    10. layout->setCanvasMargin(2,-1);
    11.  
    12. // add curves
    13. QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
    14. curveT->setPen(QPen(Qt::red,1));
    15. curveT->attach(ui->qwtPlot);
    16. QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
    17. curveP->setPen(QPen(Qt::blue,1));
    18. curveP->attach(ui->qwtPlot);
    19.  
    20. // add Axis
    21. ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100);
    22. ui->qwtPlot->setAxisFont(QwtPlot::xBottom, QFont(QString("Sans Serif"), 5, 0, false));
    23. ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -1, 1);
    24. ui->qwtPlot->setAxisFont(QwtPlot::yLeft, QFont(QString("Sans Serif"), 5, 0, false));
    To copy to clipboard, switch view to plain text mode 


    Thanks a lot

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,316
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange extra line in my plotting, help please

    The margin has no effect, when you align the scales to the canvas.

    Uwe

  5. #5
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    Hi Uwe,

    Thanks for your reply.
    Do you have any idea about the extra straight line in the end of curve?

    Thanks a lot

  6. #6
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    I solved the first problem, but i think i did it in hard way. if anyone would point me a good and right way, i will be really appreciate.
    here is my code:

    Qt Code:
    1. void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
    2. {
    3. timeCnt ++;
    4. if (timeCnt % 4 == 0)
    5. {
    6. x[chartCnt] = chartCnt;
    7. yT[chartCnt] = 0.9;
    8. yP[chartCnt] = -0.5;
    9. curveT->setRawData(x,yT,chartCnt); // here is the point
    10. ui->qwtPlot->replot();
    11. if (chartCnt < plotSize)
    12. chartCnt ++;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Uwe,

    I am not quite clear about your reply.
    in your first reply, you said:

    plotLayout()->setAlignCanvasToScales(true);
    I though i need to use setAlignCanvasToScales(true) to achieve it.

    but in your second reply, you told me
    The margin has no effect, when you align the scales to the canvas.
    do you mind give me some code please?

    Thank you very much

  7. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,316
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange extra line in my plotting, help please

    You need to understand the meaning of the different layout options - no code.

    Uwe

  8. #8
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    thanks Uwe, i will read the qwt layout class again.

  9. #9
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    Hi Uwe,

    I have tried the plotLayout()->setAlignCanvasToScales. Here is my code:
    Qt Code:
    1. ui->qwtPlot->plotLayout()->setAlignCanvasToScales(false);
    2. ui->qwtPlot->plotLayout()->setCanvasMargin(50, -1);
    To copy to clipboard, switch view to plain text mode 

    I got this:


    the length of the scale backbone has been shorted.
    What i really want is to make the scale backbone skinner. The reason is that the screen what i am running my application is only 4.3". I need get more space to display the chart. Therefore, i want to save some scale backbone space (even a little bit) to my chart. I wish the scale backbone will be looks like:



    Is that possible to achieve? Thanks for your help.

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,316
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange extra line in my plotting, help please

    Maybe plot->axisWidget(...)->setMargin(0); is what you want. You can also save some pixels by reducing the spacing and you could disable the frame of the canvas. Another idea is to disable the left axis completely and to insert a QwtPlotScaleItem on the canvas instead.

    Uwe

  11. The following user says thank you to Uwe for this useful post:

    cooper (1st November 2010)

  12. #11
    Join Date
    Jun 2009
    Location
    AKL | New Zealand
    Posts
    62
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange extra line in my plotting, help please

    Thanks Uwe,

    after i setup "setMargin(0)" and disable the frame of canvas, I got saved some pixels in my plotting screen.

    Thank for your help

Similar Threads

  1. Qmake Extra Targets
    By ChrisW67 in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 23:13
  2. Replies: 0
    Last Post: 4th August 2009, 15:24
  3. strange extra spacing between checkboxes
    By jamadagni in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2007, 10:13
  4. Qwt - extra axis
    By steg90 in forum Qwt
    Replies: 2
    Last Post: 10th July 2007, 14:41
  5. extra database features available in Qt4 than QT3
    By nimmyj in forum General Discussion
    Replies: 1
    Last Post: 24th November 2006, 22:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.