Results 1 to 11 of 11

Thread: QwtPlot: multiple curves with separate x-axis/-scales?

  1. #1
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QwtPlot: multiple curves with separate x-axis/-scales?

    hi everyone,
    first i have to say, you have a great forum here!

    even though i found alot of help here, there's an issue i couldn't solve yet, hope someone here can help me.

    i have a class which is derived from QwtPlot to display curves (own class derived from QwtPlotCurve - and yeah i know they're actually just blocks, not curves ).


    now i want to display multiple curves (unkown number), each with its own, separate x-axis (image made with gimp).


    i have tried QwtPlotScaleItem and drawing all the curves "by hand", but i couldn't get it to work well, i didn't even manage to calculate the coordinates of the curves and scale items right ...

    is there an easier way to do this or do i have to do all the calculations on my own?
    if so, i don't really know how to ... e.g. how can i draw the curves according to different scales (e.g. if the first curve has a scale from 0.0 to 5.5 and the next one has a scale from 7.0 to 12.3)? afaik they are drawn according to the "main scale" of the plot widget ...

    i'd really appreciate all help i can get here.
    i hope you can understand what i'm trying to explain here since english isn't my first language.
    thanks in advance!

    sincerely,
    julian

  2. #2
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    5
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    Take a look here :
    http://www.qtcentre.org/forum/f-qwt-...is--14504.html

    Maybe it can help.

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

    -=Freaky=- (28th August 2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    thanks for your hint viridis, i'll try it, looks good so far.
    but i have another question: how do i find out the position (on y-axis) and height of one drawn curve (in scale coords)?

    heightOfYAxis / numberOfCurves
    doesn't work of course, because it doesn't consider the extra scale items at all ... but i don't know the height of a scale item and the height doesn't change when the yLeft-scale changes (e.g. when the whole window/widget is resized) ...

    thanks in advance!
    sincerely,
    julian

  5. #4
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    5
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    Indeed, I just realized that what I was suggesting was wrong for you.
    I was wondering if you could use only one axis, and switch its scale according to the selected curve. But, by looking at your picture, it seems you always have same scales so I misunderstood the problem !

    Thus, why don't you use mulitple plots and sync them (when zooming/panning) ? It seems to me a really simple solution which do all you need.
    You do not have to worry about axis height, curve positionning...

  6. #5
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    no, you got me right first, the different x-axis can all have different scales.
    in the image they're all the same because i was too lazy to change that too when creating it with the gimp ...
    sorry for that.
    and there have to be separate axis and scales for each of the curves drawn - because my boss wants so.

    anyway, i thought about having multiple plots, but in the end i have to have one single widget ready to use and probably there's also going to be a designer-plugin for it.
    so basically, i would have to rewrite almost the whole plot-widget i have now to cover multiple plots and control dem separately, or write a whole new class covering some of my plot-widgets ... however, it would be a lot of extra work, which i'm trying to avoid ...

    big thanks for trying to help me though!

    sincerely,
    julian

  7. #6
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    sorry for double posting, but just to make my question clear again:

    i need to know how to get the height of a QwtPlotScaleItem in my code, in either pixel or scale coordinates (so i can calculate the positions of all the elements in my widget correctly).
    does anyone know how to achieve that?

    thanks in advance,
    sincerely,
    julian

  8. #7
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    hi again,

    i found QwtPlotScaleDraw::extent, is that the right method for me to use if i need the scale's height?
    if it is, i guess it's returning the height in pixel coordinates (because it's returning an integer).

    i still have some problems, but either i didn't unterstand a lot and my whole code is crap and wrong, or i just somehow can't find my mistakes ... i'd really appreciate everyone who would take a look at my code below. thanks in advance!

    so, as i said, i have a class derived from QwtPlot and another one derived from QwtPlotCurve.
    a third class is derived from QwtScaleDraw to provide easy access to some options like the label's font and the tick's and backbone's color.

    in my scale draw, i implemented the extent method like this:
    Qt Code:
    1. int MyScaleDraw::extent()
    2. {
    3. // m_labelsFont: font for labels - didn't expect this, huh? ;-)
    4. return QwtScaleDraw::extent( QPen(), m_labelsFont );
    5. }
    To copy to clipboard, switch view to plain text mode 

    in my plot class, i've got the addCurve method:
    Qt Code:
    1. void MyPlot::addCurve( MyCurve *p_curve )
    2. {
    3. if( p_curve )
    4. {
    5. setAxisScale( xBottom, 0, 5, 1 ); // just for testing purposes
    6.  
    7. double scaleHeight = 0; // height of a scale item
    8. p_curve->attach( this );
    9. if( m_curves.count() > 0 ) // m_curves: QMap< MyCurve*, QwtScaleDraw* >
    10. {
    11. s->setScaleDraw( m_xScaleDraw );
    12. s->attach( this );
    13. m_curves.insert( p_curve, s );
    14. // i'm not sure about the following:
    15. // ( m_xScaleDraw: MyScaleDraw for xBottom scales)
    16. if( m_xScaleDraw )
    17. scaleHeight = canvasMap( yLeft ).invTransform(
    18. m_xScaleDraw->extent() );
    19. }
    20. else
    21. m_curves.insert( p_curve, NULL );
    22.  
    23. double curveHeight = ( 100 - ((m_curves.count() - 1)*scaleHeight))
    24. / (m_curves.count() );
    25. QMap< MyCurve*, QwtPlotScaleItem* >::iterator it
    26. = m_curves.begin();
    27. int i = 0;
    28. while( it != m_curves.end() )
    29. {
    30. if( it.key() )
    31. {
    32. // MyCurve has 2 new elements:
    33. // height => height of the blocks
    34. // yPos => position (top border) on y-axis
    35. it.key()->setHeight( curveHeight );
    36. it.key()->setYPos( ( (i + 1) * curveHeight )
    37. + ( i * scaleHeight ) );
    38. }
    39. if( it.value() )
    40. it.value()->setPosition( it.key()->yPos()
    41. - it.key()->height() );
    42. it++;
    43. i++;
    44. }
    45. replot();
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 

    i also tested the scaleHeight values with a message box and it seems that the scaleHeight is calculated wrongly, but i just don't know why, i tried it for so long and maybe i just need a break from this project ... but i have to get this done.

    as i said, anyone willing to help here is appreciated, many thanks in advance!

    // edit: added screenshots of how it looks now after adding 2 curves to the plot widget via addCurve


    sincerely,
    julian
    Last edited by -=Freaky=-; 2nd September 2008 at 16:54.

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,278
    Thanked 872 Times in 820 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    Quote Originally Posted by -=Freaky=- View Post
    anyway, i thought about having multiple plots, but in the end i have to have one single widget ready to use and probably there's also going to be a designer-plugin for it.
    This is no argument against building your widget from several QwtPlot widgets. ( QwtPlot itsself is a composite widget ).
    IMHO this is by far the most natural and easiest implementation for your problem.

    Uwe

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

    -=Freaky=- (12th September 2008)

  11. #9
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    hi uwe,
    thanks for your reply!
    i played around with the stuff i posted above alot and finally got it to work ... at least values were calculated right and everything was drawn right.
    but it was pretty much work and you can easily have new mistakes in the code which cost alot of extra time (happened to me way too often so i really got sick of it ).

    that is basically why i'm now trying to do it the way you suggested.
    i was just about to make a new class which inherits QWidget and put a QVBoxLayout inside which will be the parent for all the plot widgets.
    is that how i should do it or is there something way better?

    again, thanks in advance!

    sincerely,
    julian

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

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    i was just about to make a new class which inherits QWidget and put a QVBoxLayout inside which will be the parent for all the plot widgets. is that how i should do it ?
    Sure,
    Uwe

  13. #11
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot: multiple curves with separate x-axis/-scales?

    alright thanks to viridis and Uwe!
    finally, i didn't need different scales for each curve, but putting QwtPlot objects together in a layout works really well so far.

    sincerely,
    julian

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.