Results 1 to 8 of 8

Thread: QwtPlot axis labels

  1. #1
    Join Date
    Aug 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtPlot axis labels

    Hi all!
    I'm on a project which generates a waveform from an audio and plots it in a qwtplot. I have that. The problem is that I dont get the values from milliseconds but from the pcm length. So my audio is 4900 milliseconds long and has over 50000 pcm data to plot then the qwtplot axis label shows the numbers to 50000. Can I divide that numbers on my label with the frequency to get the labels as milliseconds? Is there any easy way? Please explain it to me but not with the cpuplot example cause my plot isn't about that x axis labels.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot axis labels

    The best solution should be to translate the x coordinates from pcm to milliseconds. As you probably don't want to copy your samples for this I recommend to derive from QwtSeriesData<QwtPointF> and do the translation there. F.e. something like this:

    Qt Code:
    1. class YourSeriesData: public QwtSeriesData<QwtPointF>
    2. {
    3. virtual QPointF sample( size_t i ) const
    4. {
    5. // depends how you have stored your samples
    6.  
    7. double xPCM = ...;
    8. double y = ...;
    9.  
    10. return QPointF( toMS( xPCM ), y );
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

    Guess overloading YourSeriesData::boundingRect makes also sense as the x-range can be found easily for a series with increasing x values.

    HTH,
    Uwe

    PS: It's always a good idea to check the cpuplot example - even if completely unrelated when you don't want to display the tick labels in a date/time format

  3. #3
    Join Date
    Aug 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlot axis labels

    I just want the label text to show another number and dont show me 50 000 when the value is still 50 000. Can I do that in qwt? Just to change the label's "text", the numbers only. I want the plot's values to represent the pcm data because its only working that way but show in label text the ms.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot axis labels

    Then you have to study the cpuplot example

    In fact all you have to do is to derive from QwtScaleDraw and overload QwtScaleDraw::label(), where you add your pcmToMS conversion. But note that in opposite to my suggestions the scale engine calculates a scale based on pcm not on ms.

    Uwe

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

    Kutuska (29th August 2012)

  6. #5
    Join Date
    Aug 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlot axis labels

    I have this code. I think this has to work in theory. It compiles and runs but no change in text. Whats the problem in my code? If i qDebug the label's text at p it gives me the correct value but after I set the text of label(p) it won't change. Why?


    Qt Code:
    1. QwtScaleDraw *xscale = ui->qwtPlot1->axisScaleDraw(QwtPlot::xBottom);
    2. QString text;
    3. for(int p= 1; p < lenPcm; p++){
    4. text.setNum(p/freq);
    5. xscale->label(p).setText(text);
    6. }
    7. ui->qwtPlot1->setAxisScaleDraw(QwtPlot::xBottom,xscale);
    8. ui->qwtPlot1->replot();
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance!

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot axis labels

    This is your code:

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. virtual QwtText label( double v ) const
    5. {
    6. return QwtScaleDraw::label( pcmToMS( v ) );
    7. }
    8. };
    9.  
    10. plot->setAxisScaleDraw( ..., new YourScaleDraw() );
    To copy to clipboard, switch view to plain text mode 

    If you want to have ticks aligned to ms values read my first answer or set your ticks manually ( what is no option if you want to offer a navigation like zooming/panning to your users ) with QwtPlot::setAxisScaleDiv().

    HTH,
    Uwe

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

    Kutuska (29th August 2012)

  9. #7
    Join Date
    Aug 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlot axis labels

    Thanks a lot! Its working now!
    Another quick question!
    When I load a bigger file (about 3,5 mins or bigger) the Qt crashes and I think it's because qwtplot replots so much. It has to plot about 6 million dots. Its Qt's fault or there's a solution? And when I want to get a playback position indicator cursor (a vertical line) for my plot, it replots so much the Qt can't do it. Can I somehow cache the plot and then do the cursor over only the "picture" of the plot?

  10. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot axis labels

    Quote Originally Posted by Kutuska View Post
    When I load a bigger file (about 3,5 mins or bigger) the Qt crashes and I think it's because qwtplot replots so much.
    Start your debugger and check what's going on. A crash is never because the CPU is busy - it's more likely that you running out of memory.
    And when I want to get a playback position indicator cursor (a vertical line) for my plot, it replots so much the Qt can't do it. Can I somehow cache the plot and then do the cursor over only the "picture" of the plot?
    Sounds like QwtPlotPicker is what you are looking for. Check the bode example ( press the mouse on the canvas ). Instead of a cross hair you can also have a vertical or horizontal line.

    When you try to plot many many dots you might want to try Qwt from SVN trunk. It reintroduces some optimizations like:


    • QwtPlotCurve::FilterPoints
    • QwtPlotCurve::MinimizeMemory


    Especially the first flag should speed up replotting in your situation a lot. But of course the best solution is to filter out points in application code before replotting !

    Uwe

Similar Threads

  1. How to hide axis labels
    By repepo in forum Qwt
    Replies: 5
    Last Post: 10th November 2011, 09:03
  2. QWTPlot x-axis labels with float spacing
    By Pyquestor in forum Qt Programming
    Replies: 0
    Last Post: 12th May 2011, 14:40
  3. Labels on axis.
    By eugene in forum Qwt
    Replies: 5
    Last Post: 6th August 2010, 14:30
  4. Replies: 1
    Last Post: 16th March 2010, 16:23
  5. Axis with more labels
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 11th October 2009, 10:26

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.