Results 1 to 4 of 4

Thread: Align x-axis to enabled x-axis

  1. #1
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Align x-axis to enabled x-axis

    Hi,

    I'm looking for a way to align this three different plots so that they use the same x-axis (In the attached pictures you can see why it's not working).
    When I set different titles for the y-axis, my y-axis aren't aligned anymore. I did it the same way it is realised in the plotmatrix example. is there a way to consider the title of the axis?

    Qt Code:
    1. double maxExtent = 0;
    2.  
    3. const QList<QwtPlot *> Plots = this->findChildren<QwtPlot *>();
    4. foreach( QwtPlot *p, Plots ){
    5. QwtScaleWidget *scaleWidget = p->axisWidget( QwtPlot::yLeft );
    6.  
    7. QwtScaleDraw *sd = scaleWidget->scaleDraw();
    8. sd->setMinimumExtent( 0.0 );
    9.  
    10. const double extent = sd->extent( scaleWidget->font() );
    11. if ( extent > maxExtent )
    12. maxExtent = extent;
    13. }
    14.  
    15. foreach( QwtPlot *p, Plots ){
    16. QwtScaleWidget *scaleWidget = p->axisWidget( QwtPlot::yLeft );
    17.  
    18. scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
    19. }
    To copy to clipboard, switch view to plain text mode 


    Additionally I want the first plots height to be as big as possible and the others to have a minimum height. I already set vertical SizePolicy for the mainplot expanding and the others fixed.
    The number of plots in my window differs but the first one is the main plot. Also the number of curves in the other plots can be different.
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Align x-axis to enabled x-axis

    Qt Code:
    1. int margin = 30;
    2. plot->plotLayout()->setCanvasMargin( margin, QwtPlot::yLeft );
    3. plot->plotLayout()->setCanvasMargin( margin, QwtPlot::yRight );
    To copy to clipboard, switch view to plain text mode 

    helped the x-axis to be aligned when the label is on the border of the canvas.

    I would like to the set the legend of the other plots enabled and set the legend of the first plot as RightLegend.
    I set an invisible yRight-axis

    Qt Code:
    1. plot->enableAxis(QwtPlot::yRight, true);
    2. plot->axisScaleDraw(QwtPlot::yRight)->enableComponent( QwtScaleDraw::Backbone, false );
    3. plot->axisScaleDraw(QwtPlot::yRight)->enableComponent( QwtScaleDraw::Labels, false );
    4. plot->axisScaleDraw(QwtPlot::yRight)->enableComponent( QwtScaleDraw::Ticks, false );
    5.  
    6. plot->setAxisMaxMajor(QwtPlot::yRight, 0);
    7. plot->setAxisMaxMinor(QwtPlot::yRight, 0);
    8. plot->setAxisScale(QwtPlot::yRight, 0,0);
    To copy to clipboard, switch view to plain text mode 

    and tried to align the axis with following code:

    Qt Code:
    1. const QList<QwtPlot *> Plots = this->findChildren<QwtPlot *>();
    2. double maxExtent = 0;
    3. foreach( QwtPlot *p, Plots ){
    4. QwtScaleWidget *scaleWidget = p->axisWidget( QwtPlot::yRight );
    5.  
    6. QwtScaleDraw *sd = scaleWidget->scaleDraw();
    7. sd->setMinimumExtent( 0.0 );
    8.  
    9. const double legendwidth = p->plotLayout()->legendRect().width();
    10.  
    11. const double extent = sd->extent( scaleWidget->font() ) + legendwidth;
    12.  
    13. if ( extent > maxExtent )
    14. maxExtent = extent;
    15. }
    16.  
    17. double extent;
    18. foreach( QwtPlot *p, Plots ){
    19. QwtScaleWidget *scaleWidget = p->axisWidget( QwtPlot::yRight );
    20.  
    21. if ( p->objectName() == "main_plot") //object name of the first plot
    22. extent = maxExtent - p->plotLayout()->legendRect().width();
    23. else
    24. extent = maxExtent;
    25.  
    26. scaleWidget->scaleDraw()->setMinimumExtent( extent );
    27. }
    To copy to clipboard, switch view to plain text mode 

    But this didnt change anything.

    I still want to align axis when there are different sizes of labels on y-Left and the plots height to be minimum.

    GraphEx0.jpgGraphEx.jpg

  3. #3
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Align x-axis to enabled x-axis

    I think i have to overload the resize event but I still don't get how to get the size of the axis title rect.

    How can I align my axis if the label of my yLeft title takes 2 rows or more? Or if there is a label for only 1 axis?


    How do I set the width of all my legends to the same size?


    And how do I get a fixed size for my canvas and align everything in the plot to it?
    Attached Images Attached Images

  4. #4
    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: Align x-axis to enabled x-axis

    And how do I get a fixed size for my canvas and align everything in the plot to it?
    This mode doesn't exist and the fact that it is missing is the reason for all these nasty workarounds when having to align plots.

    How can I align my axis if the label of my yLeft title takes 2 rows or more?
    When you know, that some axes titles have 2 lines you can simply add a "\n" to the other axes titles.

    If the second line somehow depends on the current layout ( automatic line breaks, when the height gets too small ) you might have to add some auto detection based on QwtScaleWidget::titleHeightForWidth/QwtScaleWidget::dimForLength in the resize event of the box containing the plots.

    Uwe

Similar Threads

  1. Replies: 1
    Last Post: 21st April 2014, 21:01
  2. Axis Title to axis label alignment
    By ROCKSTAR in forum Qwt
    Replies: 0
    Last Post: 5th February 2014, 13:47
  3. Replies: 7
    Last Post: 10th July 2013, 14:32
  4. Replies: 9
    Last Post: 3rd May 2011, 22:21
  5. Replies: 0
    Last Post: 9th August 2010, 11:46

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.