Results 1 to 7 of 7

Thread: How to make curves with empty intervals in them?

  1. #1
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to make curves with empty intervals in them?

    Hello,

    I could not find anything related in Qwt docs so I'm posting here. I'm using Qwt6 SVN and I need to draw a curve (actually, a straight horizontal line), but it must not be continuous. I'm attaching a screenshot to show what I mean. The green line runs under the red one, and the red one consists of multiple pieces.
    I thought about creating multiple curves for the red one, but I need exactly one legend item for it. Preferably, the settings (color, thickness, etc...) applied to the curve should affect all its pieces.

    Any idea how I may accomplish that?

    Thanks a lot in advance!

    plot_marked.png

  2. #2
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make curves with empty intervals in them?

    Hi,
    you mean
    Qt Code:
    1. // Insert markers
    2.  
    3. // ...a horizontal line at y = 0...
    4. mY->setLabel(QString::fromLatin1("y = 0"));
    5. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    6. mY->setLineStyle(QwtPlotMarker::HLine);
    7. mY->setYValue(0.0);
    8. mY->attach(this);
    To copy to clipboard, switch view to plain text mode 
    wouldn't work for you?


    Maybe you cann ad a simple constant function:
    y = f(x) like y=1 | x[1,2]
    e.g.:
    Qt Code:
    1. // Insert new curves
    2. QwtPlotCurve *pConstantFunction = new QwtPlotCurve("y = f(1)");
    3. #if QT_VERSION >= 0x040000
    4. pConstantFunction->setRenderHint(QwtPlotItem::RenderAntialiased);
    5. #endif
    6. pConstantFunction->setPen(QPen(Qt::red));
    7. pConstantFunction->setData(....) //your const f() or an array of f(..)?
    8. pConstantFunction->attach(this);
    To copy to clipboard, switch view to plain text mode 
    or an array of functions?
    y = f(x); y=1 | x[1,2]
    y = f(x); y=1 | x[3,4]
    y = f(x); y=1 | x[7,10]

    that will simulate your seperated line?

    greetz AP.
    Last edited by Astronomy; 17th September 2010 at 13:41.

  3. The following user says thank you to Astronomy for this useful post:

    alex_sh (20th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make curves with empty intervals in them?

    Astronomy, thanks for your answer.

    Quote Originally Posted by Astronomy View Post
    Hi,
    you mean
    Qt Code:
    1. // Insert markers
    2.  
    3. // ...a horizontal line at y = 0...
    4. mY->setLabel(QString::fromLatin1("y = 0"));
    5. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    6. mY->setLineStyle(QwtPlotMarker::HLine);
    7. mY->setYValue(0.0);
    8. mY->attach(this);
    To copy to clipboard, switch view to plain text mode 
    wouldn't work for you?
    If I understand it correctly, this would not create a legend item which I need (or create multiple items? I'm not sure). A possible workaround would be to add another "dummy" curve with nothing (or a single point) to display, just to get the legend item. I would also need to mirror the curve style changes to the marker (I have a dialog that controls curve appearance). I was hoping for something a bit more straightforward.

    Maybe you cann ad a simple constant function:
    y = f(x) like y=1 | x[1,2]
    e.g.:
    Qt Code:
    1. // Insert new curves
    2. QwtPlotCurve *pConstantFunction = new QwtPlotCurve("y = f(1)");
    3. #if QT_VERSION >= 0x040000
    4. pConstantFunction->setRenderHint(QwtPlotItem::RenderAntialiased);
    5. #endif
    6. pConstantFunction->setPen(QPen(Qt::red));
    7. pConstantFunction->setData(....) //your const f() or an array of f(..)?
    8. pConstantFunction->attach(this);
    To copy to clipboard, switch view to plain text mode 
    or an array of functions?
    y = f(x) y=f(1) | x[1,2]
    y = f(x) y=f(1) | x[3,4]
    y = f(x) y=f(1) | x[7,10]

    that will simulate your seperated line?
    You mean just add one curve for each line? That would create multiple legend items (I need only one), and I would have to synchronize the curve appearance settings between them. I'll probably go with this one (once I find out how to hide the curve legend items), unless there is some simpler solution out there.

    Thanks

  5. #4
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make curves with empty intervals in them?

    Yes the first is just a horizontal line.

    The Array of constant functions will produce this:

    "_________ _________ ______________"
    f1(1). .......f2(1) .........f3(1)

    three or more f(..) at the same y-position, but with different x-points will possibly work..

    greetz AP.

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

    Default Re: How to make curves with empty intervals in them?

    1) If you want to display a curve with gaps overload QwtPlotCurve::drawXY ( don't use markers ).
    2) By curve->setItemAttribute(QwtPlotItem::Legend, ...) you can control if a curve ( or any other QwtPlotItem ) should have an entry on the legend.

    Uwe

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

    alex_sh (20th September 2010)

  8. #6
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make curves with empty intervals in them?

    Thank you both.
    I solved this by creating multiple curves and disabling the legend items (using setItemAttribute()) on all of them except the first one.
    Note that I had to disable the legend item _before_ the attach() call, or it would still allocate the space in the legend, but draw nothing there.

    P.S. There's no QwtPlotCurve::drawXY() in Qwt6, or am I mistaken?

  9. #7
    Join Date
    Oct 2010
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make curves with empty intervals in them?

    Hi,
    I have resolved this problem to using nan values, see the attached files
    qwt_plot_piecewise_curve.h
    qwt_plot_piecewise_curve.cpp

  10. The following user says thank you to Galak for this useful post:

    alex_sh (26th October 2010)

Similar Threads

  1. Information about curves
    By den in forum Qwt
    Replies: 1
    Last Post: 27th April 2010, 19:02
  2. Select multiple curves
    By aimsc in forum Qwt
    Replies: 2
    Last Post: 30th October 2009, 10:45
  3. Multiple curves on top of each other
    By jmsbc in forum Qwt
    Replies: 2
    Last Post: 15th July 2009, 19:46
  4. Replies: 2
    Last Post: 12th September 2008, 08:43
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30

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.