Results 1 to 3 of 3

Thread: qwtplot drawing lines with negative values

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default qwtplot drawing lines with negative values

    Good day to you!
    I'm trying to draw lines on my QwtPlot graph, and using this construction:
    Qt Code:
    1. ui_plot->setAutoFillBackground(true);
    2. ui_plot->setCanvasBackground(QColor(0xE3E3E3));
    3. ui_plot->setAxisScale(QwtPlot::yLeft, -1, 1);
    4. ui_plot->setAxisScale(QwtPlot::xBottom, -1, 1);
    5. ui_plot->enableAxis(QwtPlot::yLeft, true);
    6. ui_plot->enableAxis(QwtPlot::xBottom, true);
    7. QwtPlotCurve *xline = new QwtPlotCurve();
    8. QwtPlotCurve *yline = new QwtPlotCurve();
    9.  
    10. double x[3] ={-1.0, 0.0, 1.0};
    11. double y[3] ={0,0,0};
    12.  
    13. xline->setData(new QwtCPointerData(x,y,(size_t)3));
    14. xline->setPen(QPen(QColor(Qt::black)));
    15. xline->attach(ui_plot);
    16. ui_plot->replot();
    To copy to clipboard, switch view to plain text mode 

    I expect to have line, drawn from -1 to 1. But for some reason i always receive line from 0 to +∞. It's weird and i really want to know, what kind of data i should use to draw a simple x[-1;0;1] y[0;0;0] line. Can you help me please?

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

    Default Re: qwtplot drawing lines with negative values

    Guess x/y are on the stack and get overwritten by some random data.

    Uwe

  3. #3
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qwtplot drawing lines with negative values

    I solved it this way:
    Qt Code:
    1. double x1[3] = {-1.5, 0, 1.5};
    2. double y1[3] = {0, 0, 0};
    3. double x2[3] = {0, 0, 0};
    4. double y2[3] = {-1.5, 0, 1.5};
    5.  
    6. x_1_line->setSamples(x1,y1,3);
    7. y_1_line->setSamples(x2,y2,3);
    8.  
    9. x_1_line->setPen(QPen(QColor(Qt::black),1,Qt::DashLine));
    10. y_1_line->setPen(QPen(QColor(Qt::black),1,Qt::DashLine));
    11.  
    12. x_1_line->attach(ui_plot);
    13. y_1_line->attach(ui_plot);
    14.  
    15. ui_plot->replot();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 24th November 2016, 09:04
  2. Drawing lines on qwtpolarplot
    By jerrychan in forum Qwt
    Replies: 3
    Last Post: 12th June 2013, 11:55
  3. drawing lines using qpainter from file
    By neutrino in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2013, 10:03
  4. Replies: 2
    Last Post: 7th July 2009, 08:44
  5. How to get multiple lines values in XML file..
    By dark1988 in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2008, 09:24

Tags for this Thread

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.