Results 1 to 10 of 10

Thread: aligning plots and color bar

  1. #1
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default aligning plots and color bar

    Hi,

    I need to align 2 plots : one containing a QwtPlotCurve and the other one a QwtPlotSpectrogram. Both are arranged in a vertical layout (QVBoxLayout - it's a waterfall plot).

    I used some parts of the example (playground) "plotmatrix" to ensure that both plots stay aligned. BUT, there's one problem : when enabling the QwtPlotSpectrogram's right axis color bar, the plots are no more aligned.

    can "plotmatrix" be easily updated to take in account the width of the color bar ?

    Another solution is to create a 2x2 QGridLayout, put the curve in (0,0), the spectrogram in (1,0) and a QwtScaleWidget (with a color bar enabled) in (1,1). Otherwise, if having the yRight + color bar axis enabled on the QwtPlotCurve plot is not annoying, that also will fix the alignment issue.

    Thanks.

  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: aligning plots and color bar

    The plotMatrix example is aligning the vertical scales by using QwtScaleDraw::setMiniumExtent.
    So your code is probably somehow like this ( untested ):

    Qt Code:
    1. auto s1 = spectrogramPlot->axisWidget( QwtPlot::yRight );
    2. auto s2 = curvePlot->axisWidget( QwtPlot::yRight );
    3.  
    4. s2->scaleDraw()->setMinimumExtent( 0.0 );
    5.  
    6. qreal extent = s1->scaleDraw()->extent( s1->font() );
    7. extent -= s2->extent( s2->font() );
    8. extent += s1->colorBarWidth() + s1->spacing();
    9.  
    10. s2->scaleDraw()->setMinimumExtent( extent );
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. #3
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: aligning plots and color bar

    Hi Uwe,

    It didn't work I also used your code snippet in in the plot matrix example and it didn't work too.

    aligning_waterfall_axis_issue.png

    I think I'll do plan B : using a separate QwtScale widget to handle spectrogram's color bar. I really don't like this solution, it's cumbersome.

    I'll be very happy if you can help me to fix my problem : https://github.com/embeddedmz/QwtWaterfallplot I'm struggling with it since this last summer.

    Thanks.

  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: aligning plots and color bar

    Quote Originally Posted by embeddedmz View Post
    It didn't work I also used your code snippet in in the plot matrix example and it didn't work too.
    It didn't work is not a very helpful information. Don't you you have an effect when increasing the minimum extent for the right axis of the upper plot ?

    Uwe

  5. #5
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: aligning plots and color bar

    You're right Uwe !

    Now it looks better but there's still some adjustments that have to be made and I hope that you can help me :

    aligning_waterfall_plot_axis_progress.jpg

    First of all, there's these 2 lines in the constructor that triggers everything, the issue is that if I don't rescale X axis of one of the two plots, the alignement logic will not be executed and I don't know how to handle this (plotmatrix playground). For example, to obtain the result shown in the screenshot above, I used the zoomer to zoom a region of the waterfall.

    Qt Code:
    1. connect(m_plotCurve->axisWidget(QwtPlot::xBottom), &QwtScaleWidget::scaleDivChanged,
    2. this, &Waterfallplot::scaleDivChanged/*, Qt::QueuedConnection*/);
    3. connect(m_plotSpectrogram->axisWidget(QwtPlot::xBottom), &QwtScaleWidget::scaleDivChanged,
    4. this, &Waterfallplot::scaleDivChanged/*,Qt::QueuedConnection*/);
    5.  
    6. void Waterfallplot::scaleDivChanged()
    7. {
    8. // apparently, m_inScaleSync is a hack that can be replaced by
    9. // blocking signals on a widget but that could be cumbersome
    10. // or not possible as the Qwt API doesn't provide any mean to do that
    11. if (m_inScaleSync)
    12. {
    13. return;
    14. }
    15. m_inScaleSync = true;
    16.  
    17. QwtPlot* updatedPlot;
    18. if (m_plotCurve->axisWidget(QwtPlot::xBottom) == sender())
    19. {
    20. updatedPlot = m_plotCurve;
    21. }
    22. else if (m_plotSpectrogram->axisWidget(QwtPlot::xBottom) == sender())
    23. {
    24. updatedPlot = m_plotSpectrogram;
    25. }
    26. else
    27. {
    28. updatedPlot = nullptr;
    29. }
    30.  
    31. if (updatedPlot)
    32. {
    33. QwtPlot* plotToUpdate = (updatedPlot == m_plotCurve) ? m_plotSpectrogram : m_plotCurve;
    34. plotToUpdate->setAxisScaleDiv(QwtPlot::xBottom,
    35. updatedPlot->axisScaleDiv(QwtPlot::xBottom));
    36. updateLayout();
    37. }
    38.  
    39. m_inScaleSync = false;
    40. }
    41.  
    42. void Waterfallplot::alignAxis(int axisId)
    43. {
    44. // 1. Align Vertical Axis (only left or right)
    45. double maxExtent = 0;
    46.  
    47. {
    48. QwtScaleWidget* scaleWidget = m_plotCurve->axisWidget(axisId);
    49.  
    50. QwtScaleDraw* sd = scaleWidget->scaleDraw();
    51. sd->setMinimumExtent(0.0);
    52.  
    53. const double extent = sd->extent(scaleWidget->font());
    54. if (extent > maxExtent)
    55. {
    56. maxExtent = extent;
    57. }
    58. }
    59.  
    60. {
    61. QwtScaleWidget* scaleWidget = m_plotSpectrogram->axisWidget(axisId);
    62.  
    63. QwtScaleDraw* sd = scaleWidget->scaleDraw();
    64. sd->setMinimumExtent( 0.0 );
    65.  
    66. const double extent = sd->extent(scaleWidget->font());
    67. if (extent > maxExtent)
    68. {
    69. maxExtent = extent;
    70. }
    71. }
    72.  
    73. {
    74. QwtScaleWidget* scaleWidget = m_plotCurve->axisWidget(axisId);
    75. scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
    76. }
    77.  
    78. {
    79. QwtScaleWidget* scaleWidget = m_plotSpectrogram->axisWidget(axisId);
    80. scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
    81. }
    82. }
    83.  
    84. void Waterfallplot::alignAxisForColorBar()
    85. {
    86. auto s1 = m_plotSpectrogram->axisWidget(QwtPlot::yRight);
    87. auto s2 = m_plotCurve->axisWidget(QwtPlot::yRight);
    88.  
    89. s2->scaleDraw()->setMinimumExtent( 0.0 );
    90.  
    91. qreal extent = s1->scaleDraw()->extent(s1->font());
    92. extent -= s2->scaleDraw()->extent(s2->font());
    93. extent += s1->colorBarWidth() + s1->spacing();
    94.  
    95. s2->scaleDraw()->setMinimumExtent(extent);
    96. }
    97.  
    98. void Waterfallplot::updateLayout()
    99. {
    100. // 1. Align Vertical Axis (only left or right)
    101. alignAxis(QwtPlot::yLeft);
    102. alignAxisForColorBar();
    103.  
    104. // 2. Replot
    105. m_plotCurve->replot();
    106. m_plotSpectrogram->replot();
    107. }
    To copy to clipboard, switch view to plain text mode 

    Please can you take a look at what I did : https://github.com/embeddedmz/QwtWaterfallplot and help me to enhance it.

    I think it's a good idea to create a new Qwt example, for the data one can use the spectrogram example data and display it slowly ! Otherwise, I'm going to add a curve plot at the left of the spectrogram, and that will allow a user to select a point on the spectrogram and use the curve plot above the waterfall to plot the layer in function of the spectrogram X axis and the the curve plot at the left of the spectrogram will be used to plot the vertical waterfall slice in function of time (the curves reflects the cross described by the point). I think this is a better example.

    Thanks.
    Attached Images Attached Images
    Last edited by embeddedmz; 21st January 2020 at 11:46.

  6. #6
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: aligning plots and color bar

    I managed to fix all the issues even though that led me to write ugly code, but the final result is awesome :

    waterfall_final.jpg

  7. #7
    Join Date
    Jan 2020
    Location
    Brighton
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: aligning plots and color bar

    Quote Originally Posted by embeddedmz View Post
    I managed to fix all the issues even though that led me to write ugly code, but the final result is awesome :

    waterfall_final.jpg
    I have the same problem!

  8. #8
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: aligning plots and color bar

    What problem ?

  9. #9
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: aligning plots and color bar

    Oh crap, when setting spectrogram and X/Y/Z titles, that broke the alignments of both curves with the spectrogram.

    Dear Uwe, how can I determine the amount of space (pixels ?) that the titles are occupying ? Can you please help me to fix this issue just like you did with the color bar ? Thank you.

    By the way, I played with the "plotmatrix" example, and it doesn't take in account the plot's titles !
    Last edited by embeddedmz; 30th January 2020 at 11:02.

  10. #10
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: aligning plots and color bar

    Encountered the same problem. When one plot uses colorbar and another one does not, 'plotmatrix' example does not work. Colorbar is not covered by scale extents.

    My solution was to create fictitious invisible axis with colorbar.

Similar Threads

  1. Vertically aligning multiple plots
    By SeanM in forum Qwt
    Replies: 7
    Last Post: 31st January 2014, 08:05
  2. Aligning QwtLegend to QwtPlot
    By bisasatan in forum Qwt
    Replies: 3
    Last Post: 15th May 2013, 13:51
  3. Replies: 3
    Last Post: 8th April 2013, 08:06
  4. Aligning 2 plots
    By jerrychan in forum Qwt
    Replies: 2
    Last Post: 25th February 2013, 09:12
  5. Aligning a stringlist
    By impeteperry in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2006, 18:45

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.