Results 1 to 4 of 4

Thread: synchronize the X-axis of two plots

  1. #1
    Join Date
    Nov 2008
    Location
    Berlin, Germany
    Posts
    13
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default synchronize the X-axis of two plots

    I have two QwtPlot diagrams that are in a vertical layout. The X axes have the same scale. The Y-axes have different scales and the bottom diagram has a second Y-axis at the right side. This leads to the effect that the X positions are not aligned to each other, making it difficult to interpret the corresponding values. How can I make sure that all corresponding X positions are aligned?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: synchronize the X-axis of two plots

    Is your problem the second Y axis that makes the plot smaller thus disaligning the plots?
    If yes, then you could use setContentsMargin() on the plot without extra Y axis and set the right margin to the axis widget width.
    If no, then I didn't understood your problem.

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

    eehmke (20th February 2012)

  4. #3
    Join Date
    Nov 2008
    Location
    Berlin, Germany
    Posts
    13
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: synchronize the X-axis of two plots

    Quote Originally Posted by Spitfire View Post
    Is your problem the second Y axis that makes the plot smaller thus disaligning the plots?
    If yes, then you could use setContentsMargin() on the plot without extra Y axis and set the right margin to the axis widget width.
    Thanks, will try that.
    It's not only that the first plot does not have a right Y axis. Also the left Y axes have different size because the scale is different (large numbers as major ticks). The contentmargin of the plots seems always to be (0, 0, 0, 0)


    Added after 20 minutes:


    Ok it works when I put some experimental values into the content margin. Next step would be to calculate them from the font size used to draw the scale ticks. Thanks!
    Last edited by eehmke; 20th February 2012 at 12:47.

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: synchronize the X-axis of two plots

    You can tackle different sizes of Y axis widget by setting minimum extent:
    Qt Code:
    1. QwtScaleDraw* sd = plot->axisScaleDraw( QwtPlot::yLeft );
    2. sd->setMinimumExtent( 50 ); // magic number
    3. plot->setAxisScaleDraw( QwtPlot::yLeft, sd );
    To copy to clipboard, switch view to plain text mode 
    this way the widget will be at least that wide. Using that you can ensure that width of the widget is the same across different plots.

  6. The following user says thank you to Spitfire for this useful post:

    eehmke (12th March 2012)

Similar Threads

  1. Replies: 9
    Last Post: 3rd May 2011, 21:21
  2. Replies: 0
    Last Post: 9th August 2010, 10:46
  3. Synchronize with Editor
    By dwarnold45 in forum Newbie
    Replies: 0
    Last Post: 31st March 2010, 04:40
  4. synchronize threads
    By weixj2003ld in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2009, 07:08
  5. synchronize two QSplitters
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2007, 17: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
  •  
Qt is a trademark of The Qt Company.