Results 1 to 10 of 10

Thread: aligning plots and color bar

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #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 10:46.

Similar Threads

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