[SOLVED] 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 (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.


  • Lifetime Qt Champion

    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



  • 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


  • Lifetime Qt Champion

    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 :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.