Results 1 to 3 of 3

Thread: qwtspectrogram axis adjustment for area not pixels

  1. #1
    Join Date
    Sep 2014
    Posts
    10
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default qwtspectrogram axis adjustment for area not pixels

    Hi I am using qwtspectrogram to plot my array data but the problem i am having is scaling.. the qwt scales are distributed over the intervals x and y and the axis are dependent on the pixels. for example if I have a data set of (500×500) and i want to plot for 500mm x500mm its perfect because it is translated over the pixels but if i want to plot 500×500 number of points for 300mmx300mm it is a mess and it shows in the plot 500×500 i know i have to manage the x and y axis but I have no idea how to do that. I manage to play a little and display 500×500 for 250mmx250mm area but can not do for others.
    my code is as shown below

    Qt Code:
    1. class mydata: public QwtRasterData
    2. {
    3. char filepath[35];
    4. QFile myfile;
    5. QVector<qint16> fileBuf;
    6. int pixel =500; // it represents the number of pixels in one row or column
    7. int dial =1000;
    8. public:
    9.  
    10. mydata()
    11. {
    12. setInterval( Qt::XAxis, QwtInterval( 0, (pixel)-1 ) );
    13. setInterval( Qt::YAxis, QwtInterval( 0, (pixel)-1 ) );
    14. setInterval( Qt::ZAxis, QwtInterval( -dial, dial ) );
    15.  
    16. {
    17. sprintf_s(filepath, "c:\\myfile.bin");
    18.  
    19. myfile.setFileName(filepath);
    20. if(!myfile.open(QIODevice::ReadOnly)) return;
    21.  
    22. QDataStream data(&myfile);
    23. data.setByteOrder(QDataStream::LittleEndian);
    24.  
    25. while(!data.atEnd()) {
    26. qint16 x;
    27. data >> x;
    28. fileBuf.append(x);
    29. }
    30.  
    31. myfile.close();
    32. }
    33. }
    34.  
    35. virtual double value( double x, double y ) const
    36. {
    37. int x_pos = static_cast<int>(x);
    38. int y_pos = static_cast<int>(y);
    39. double c = (fileBuf[ ((x_pos)+((pixel-(y_pos))*pixel))]);
    40. return c;
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 
    in short i have same number of pixels for different areas but i have same representation of axis in plot.

  2. #2
    Join Date
    Sep 2014
    Posts
    10
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qwtspectrogram axis adjustment for area not pixels

    here is a class that converts double value of scale into string and display instead

    Qt Code:
    1. class MyScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. MyScaleDraw()
    5. {
    6. setTickLength( QwtScaleDiv::MajorTick, 10 );
    7. setTickLength( QwtScaleDiv::MinorTick, 2 );
    8. setTickLength( QwtScaleDiv::MediumTick, 0 );
    9.  
    10. setLabelRotation( 0 );
    11. setLabelAlignment( Qt::AlignLeft | Qt::AlignVCenter );
    12.  
    13. setSpacing( 10 );
    14. }
    15.  
    16. virtual QwtText label( double value ) const
    17. {
    18. QwtText h=QwtText(QString::number(value*0.75); //use any scaling factor you want
    19. return h;
    20. }
    21. };
    To copy to clipboard, switch view to plain text mode 

    include the following below code after creating a plot


    Qt Code:
    1. d_plot->setAxisScaleDraw( QwtPlot::xBottom, new MyScaleDraw() );
    2. d_plot->setAxisScaleDraw( QwtPlot::yLeft, new MyScaleDraw() );
    To copy to clipboard, switch view to plain text mode 

    this solved my problem

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qwtspectrogram axis adjustment for area not pixels

    I'm not 100% sure if I understand your initial mail exactly, but it looks like all you want to is to display a 500x500 matrix of values inside an area of a different size ( f.e 100x200 ) in plot coordinates :

    Qt Code:
    1. rasterdata->setInterval( Qt::XAxis, QwtInterval( 0.0, 100 ) );
    2. rasterdata->setInterval( Qt::YAxis, QwtInterval( 0.0, 200 ) );
    To copy to clipboard, switch view to plain text mode 
    If you are using QwtMatrixRaterData this would be all, otherwise it might be a good idea to implement YourRasterData::pixelHint() returning the size of one data pixel.

    With using your label transformation you are faking a different coordinate system to the user, than the one that is used by the plot. You will have effects, that the ticks are not aligned to your faked coordinate system, labels at other places ( picker/zoom ) might be wrong etc.

    Uwe

Similar Threads

  1. Replies: 1
    Last Post: 11th February 2014, 21:31
  2. QTreeView automatic Widget Height adjustment
    By mqt in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2013, 11:42
  3. Replies: 5
    Last Post: 28th November 2011, 07:20
  4. Replies: 1
    Last Post: 8th October 2011, 19:15
  5. How to adddata for qwtspectrogram
    By centroid in forum Qwt
    Replies: 2
    Last Post: 2nd August 2010, 13:36

Tags for this Thread

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.