Results 1 to 3 of 3

Thread: Problem with QwtPlotSpectrogram: completely gray output

  1. #1
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Problem with QwtPlotSpectrogram: completely gray output

    Dear all,

    I have the following problem. I would like to visualize a two-dimensional grid in which agents move. They all have a certain value which I like to visualize using colours, that is why I like to use QwtPlotSpectrogram. However, after reading various examples and implementing code, my grid stays gray, and none of the colours are displayed.

    This is my code:

    In the constructor of mainwindow.cpp:

    Qt Code:
    1. //Colormap
    2. colormap = new QwtLinearColorMap(Qt::darkCyan, Qt::red);
    3. colormap->addColorStop(0.1, Qt::cyan);
    4. colormap->addColorStop(0.6, Qt::green);
    5. colormap->addColorStop(0.95, Qt::yellow); //empty paradigm different color from all other paradigms
    6.  
    7. //Grid
    8. grid_qwtSpectPLot = new QwtPlotSpectrogram;
    9. grid_qwtSpectPLot->attach(ui->grid_qwtPlot);
    10. grid_qwtSpectPLot->setDisplayMode(QwtPlotSpectrogram::ImageMode, true);
    11. grid_qwtSpectPLot->setColorMap(colormap);
    12. grid_qwtSpectPLot->setRenderThreadCount(0);
    13.  
    14. //Matrix
    15. matrixdata = new QwtMatrixRasterData;
    16. matrixdata->setInterval(Qt::XAxis,QwtInterval(0,99,QwtInterval::IncludeBorders));
    17. matrixdata->setInterval(Qt::YAxis,QwtInterval(0,99,QwtInterval::IncludeBorders));
    18.  
    19. grid_qwtSpectPLot->attach(ui->grid_qwtPlot);
    20. ui->grid_qwtPlot->setTitle(QString("Grid"));
    21. ui->grid_qwtPlot->plotLayout()->setAlignCanvasToScales(true);
    To copy to clipboard, switch view to plain text mode 

    And two methods which are called during the simulation. Nigel_DeJong is the object which represents the agents on a grid and maxvalue makes sure the values are between 0 and 1. grid is a QVector consisting out of doubles.
    Qt Code:
    1. //Get the data to display the grid
    2. void MainWindow::getDataGrid()
    3. {
    4. int l=0;
    5. for(int j=0; j<L; j++){
    6. for(int k=0; k<L; k++){
    7. grid.append(float(Nigel_DeJong->get_value)/maxvalue);
    8. l++;
    9. }
    10. }
    11. }
    12.  
    13. //Update the grid
    14. void MainWindow::viewGrid()
    15. {
    16. getDataGrid();
    17. matrixdata->setValueMatrix(grid,L);
    18. grid_qwtSpectPLot->setData(matrixdata);
    19. ui->grid_qwtPlot->replot();
    20. grid.clear();
    21. }
    To copy to clipboard, switch view to plain text mode 

    I checked the values in the matrix, and it is filled with doubles between 0 and 1. Does anyone see what results in a completely grey grid?

    Much thanks in advance.

  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: Problem with QwtPlotSpectrogram: completely gray output

    At least one thing that is missing in your code is setting a valid range:

    Qt Code:
    1. matrixdata->setInterval( Qt::ZAxis, QwtInterval(min, max ) );
    To copy to clipboard, switch view to plain text mode 
    min corresponds with 0.0 in the color map, max with 1.0.

    Uwe

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

    prubbens (3rd September 2013)

  4. #3
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Problem with QwtPlotSpectrogram: completely gray output

    Thanks, this solved my problem.

Similar Threads

  1. QwtPlotSpectrogram rows and columns problem
    By raulchernobyl in forum Qwt
    Replies: 2
    Last Post: 23rd November 2012, 12:03
  2. Replies: 13
    Last Post: 22nd August 2011, 21:12
  3. Disabling does not gray-out buttons
    By lotek in forum Newbie
    Replies: 4
    Last Post: 13th October 2010, 11:48
  4. dark gray style
    By gjaegy in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 00:39
  5. dark gray widgets/background
    By momesana in forum Qt Programming
    Replies: 8
    Last Post: 17th June 2007, 10:39

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.