Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] qwtspectrogram axis adjustment for area not pixels
QtWS25 Last Chance

[SOLVED] qwtspectrogram axis adjustment for area not pixels

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    habbas33
    wrote on last edited by
    #1

    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 (500x500) and i want to plot for 500mm x500mm its perfect because it is translated over the pixels but if i want to plot 500x500 number of points for 300mmx300mm it is a mess and it shows in the plot 500x500 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 500x500 for 250mmx250mm area but can not do for others.
    my code is as shown below

    @class mydata: public QwtRasterData
    {
        char filepath[35];
        QFile myfile;
        QVector<qint16> fileBuf;
        int pixel =500; // it represents the number of pixels in one row or column
        int dial =1000;
    public:
    
    mydata()
        {
        setInterval( Qt::XAxis, QwtInterval( 0, (pixel)-1 ) );
        setInterval( Qt::YAxis, QwtInterval( 0, (pixel)-1 ) );
        setInterval( Qt::ZAxis, QwtInterval( -dial, dial ) );
    
        {
         sprintf_s(filepath, "c:\\myfile.bin");
       
         myfile.setFileName(filepath);
         if(!myfile.open(QIODevice::ReadOnly)) return;
    
         QDataStream data(&myfile);
         data.setByteOrder(QDataStream::LittleEndian);
    
         while(!data.atEnd()) {
             qint16 x;
             data >> x;
             fileBuf.append(x);
         }
    
         myfile.close();
     }
    }
    
    virtual double value( double x, double y ) const//shifted
    {
    int x_pos = static_cast<int>(x);
    int y_pos = static_cast<int>(y);
    double c =  (fileBuf[ ((x_pos)+((pixel-(y_pos))*pixel))]);
    return c;
    }
    }@
    

    in short i have same number of pixels for different areas but i have same representation of axis in plot.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      IIRC there was something like QwtScaleEngine or something for that part (but it's been a long time since I used these).

      You should also try asking the Qwt guys

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        habbas33
        wrote on last edited by
        #3

        hi, thanks for your reply. I manage to find the answer.

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

        @ class MyScaleDraw: public QwtScaleDraw
        {
        public:
        MyScaleDraw()
        {
        setTickLength( QwtScaleDiv::MajorTick, 10 );
        setTickLength( QwtScaleDiv::MinorTick, 2 );
        setTickLength( QwtScaleDiv::MediumTick, 0 );

                setLabelRotation( 0 );
                setLabelAlignment( Qt::AlignLeft | Qt::AlignVCenter );
        
                setSpacing( 10 );
            }
        
            virtual QwtText label( double value ) const
            {
                QwtText h=QwtText(QString::number(value*0.75); //use any scaling factor you want
                return h;
            }
        };@
        

        include the following below code after creating a plot

        @ d_plot->setAxisScaleDraw( QwtPlot::xBottom, new MyScaleDraw() );
        d_plot->setAxisScaleDraw( QwtPlot::yLeft, new MyScaleDraw() );@

        this solved my problem

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Nice you found out and thanks for sharing !

          Don't forget to update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved