I need a plot to maintain a 1:1 aspect ratio, but I'll occasionally change the data. When I try this, the axes don't appear to be altered to fit the new range of the data. For example, when I initially plot a long line (going from (0,0) to (20,20), say), I get the expected behavior; the plot maintains the 1:1 aspect ratio when resizing. But if I then setData() to a shorter line (say, (0,0) to (10,10)), the axes remain the same, and there's a lot of unused space in the plotting area. How do I get the axes to readjust to the new range of the data and keep a 1:1 aspect ratio?

I'm using Qt 4.6.2, Qwt 5.2.1, and GCC 4.5.0 on CentOS 4.

A crude example follows. main.h:
Qt Code:
  1. #include <QWidget>
  2.  
  3.  
  4. class QwtPlot;
  5. class QwtPlotRescaler;
  6.  
  7.  
  8. class Window : public QWidget
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. Window( QWidget* parent = 0 );
  14.  
  15. private:
  16. QwtPlot* plot;
  17. QwtPlotCurve* curve;
  18. QwtPlotRescaler* rescaler;
  19. QPushButton* switchDataButton;
  20. QHBoxLayout* layout;
  21.  
  22. private slots:
  23. void switchData();
  24. };
To copy to clipboard, switch view to plain text mode 
main.cpp:
Qt Code:
  1. #include "main.h"
  2. #include "qwt_plot.h"
  3. #include "qwt_plot_curve.h"
  4. #include "qwt_plot_rescaler.h"
  5. #include <QtGui>
  6.  
  7.  
  8. const double HI = 20.0;
  9. const double LO = 10.0;
  10. const int N = 5;
  11. const double DATA_HI[] = { 0.0, 0.25*HI, 0.5*HI, 0.75*HI, HI };
  12. const double DATA_LO[] = { 0.0, 0.25*LO, 0.5*LO, 0.75*LO, LO };
  13.  
  14.  
  15. Window::Window( QWidget* parent ) : QWidget( parent )
  16. {
  17. resize( 400, 500 );
  18.  
  19. plot = new QwtPlot( this );
  20. curve = new QwtPlotCurve;
  21. curve->setData( DATA_HI, DATA_HI, N );
  22. curve->attach( plot );
  23. rescaler = new QwtPlotRescaler( plot->canvas() );
  24. rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
  25.  
  26. switchDataButton = new QPushButton( "Switch data", this );
  27. connect( switchDataButton, SIGNAL( clicked() ),
  28. this, SLOT( switchData() ) );
  29.  
  30. layout = new QHBoxLayout;
  31. layout->addWidget( plot );
  32. layout->addWidget( switchDataButton );
  33. setLayout( layout );
  34.  
  35. plot->replot();
  36. }
  37.  
  38.  
  39. void Window::switchData()
  40. {
  41. if ( curve->maxYValue() > LO ) curve->setData( DATA_LO, DATA_LO, N );
  42. else curve->setData( DATA_HI, DATA_HI, N );
  43. plot->updateAxes(); // This doesn't make a difference that I can tell
  44. plot->replot();
  45. rescaler->rescale();
  46. }
  47.  
  48.  
  49. int main( int argc, char* argv[] )
  50. {
  51. QApplication app( argc, argv );
  52.  
  53. Window window;
  54. window.show();
  55.  
  56. return app.exec();
  57. }
To copy to clipboard, switch view to plain text mode 

Thanks!