Results 1 to 6 of 6

Thread: QwtPlot x axis label

  1. #1
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QwtPlot x axis label

    Hello all,

    I have a QwtPlot that is in real time and sliding. I want to have 400 x values visable. Initially the x axis was auto scaling and being deleted on the left and increasing on the right. This looks really bad. I want it to have the graph look like it is going off the page on both left and right.

    I accomplished this with this function call:

    plot->setAxisMaxMajor(QwtPlot::xBottom, 400);

    Now the problem is I have 400 numbers marking each x axis tick. I have been looking around to no avail for a function to limit these numbers and only show maybe 4 with intervals of 100.

    Can someone help me please? Thank you!
    Last edited by ldg20; 12th July 2012 at 20:00.

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

    Default Re: QwtPlot x axis label

    Quote Originally Posted by ldg20 View Post
    I have a QwtPlot that is in real time and sliding. I want to have 400 x values visable. Initially the x axis was auto scaling and being deleted on the left and increasing on the right. This looks really bad. I want it to have the graph look like it is going off the page on both left and right.
    There are several option how to configure the auto-scaler and the layout of a plot. Unfortunately I didn't understand what you tried and what didn't work. So it is hard to say if there is an easy solution, but maybe QwtLinearScaleEngine::Floating is what you are looking for ?

    Note that you can turn off autoscaling by assigning the range manually: QwtPlot::setAxisScale. The scale engine will find reasonable ticks regardless if the range is the result of autoscaling or manually assigned.

    Now the problem is I have 400 numbers marking each x axis tick. I have been looking around to no avail for a function to limit these numbers and only show maybe 4 with intervals of 100.
    There are major, medium and minor ticks - major ticks usually have tick labels. So what you are looking for is probably a scale with 5 major ticks at 0, 100, 200, 300, 400 - maybe medium ticks at 50, 150, 250, 350 and a reasonable number of minor ticks for the remaining multiples of 10 - but this is what you should get from the scale engine, when you use setAxisMaxMajor/setAxisMaxMinor with the right parameters.

    If you really need to suppress tick labels you can overload QwtScaleDraw::label() returning QString::null for certain values or you could increase the minor/medium tick length to the same size as the major ticks using QwtScaleDraw::setTickLength(). But both are hacks - only do this, when there is really no way so that the scale engine returns, what you need.

    Last but not least note, that you can assign all ticks manually using QwtPlot::setAxisScaleDiv().

    Uwe

  3. #3
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlot x axis label

    Thank you Uwe for responding.

    I am usuing Qwt 5.0

    I think pictures will explain best.

    My graph is a sliding window of x,y values. The sliding window first begins showing the values 0 - 400 of x, then 1 - 401, 2 - 402 and so on.

    This is what I had. Notice the autoscaler seems to cut off values in the beginning and leaves room at the end for values not yet in the attatched data.
    Screenshot from 2012-07-12 12:02:35.jpg

    After the call to setAxisMaxMajor I get this. Note my only reason for that call is to limit the x window size to values that will be plotted. Maybe there is a better function to suite my needs without inflicting me with the problem of too many major x labels.
    Screenshot from 2012-07-12 14:51:03.jpg


    Thanks.
    Last edited by ldg20; 13th July 2012 at 00:06.

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

    Default Re: QwtPlot x axis label

    Quote Originally Posted by ldg20 View Post
    Notice the autoscaler seems to cut off values in the beginning and leaves room at the end for values not yet in the attatched data.
    To disable the alignment at the end of the axes:
    Qt Code:
    1. plot->axisScaleEngine( QwtPlot::xBottom )->setAttribute( QwtScaleEngine::Floating, true );
    To copy to clipboard, switch view to plain text mode 
    You might also want to set do the following, for the situation when the tick labels are close to the borders:

    Qt Code:
    1. plot->plotLayout()->setAlignCanvasToScales( true );
    To copy to clipboard, switch view to plain text mode 
    But I still didn't get what you mean by "cut off values in the beginning": what is the bounding rectangle of the 400 points and what ranges on the scales do you want to display ?

    Note that in your case auto scaling is not of much interest as you could simply do the following:

    Qt Code:
    1. int startIndex = ...
    2. plot->setAxisScale( QwtPlot::xBottom, points[ startIndex ].x(), points[ startIndex + 400 ].x(), );
    To copy to clipboard, switch view to plain text mode 

    Uwe

  5. #5
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlot x axis label

    Thanks for all the help Uwe.

    plot->axisScaleEngine( QwtPlot::xBottom )->setAttribute( QwtScaleEngine::Floating, true );

    was exactly what I needed.

    I have another question now. Is the QwtPlot double buffered? My plot is very data intensive and I'm just looking for ways now to make it more fluid and easy to look at. Any ideas? Thanks again!

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

    Default Re: QwtPlot x axis label

    Quote Originally Posted by ldg20 View Post
    I have another question now. Is the QwtPlot double buffered?
    In the default configuration it is triple buffered. Double buffering is already done by Qt for any widget and the 3rd buffer avoids replots in combination with overlays ( f.e the rubberband of the zoomer ). You can disable both buffers, but beside for live plots I don't see any good reason why.

    Quote Originally Posted by ldg20 View Post
    My plot is very data intensive and I'm just looking for ways now to make it more fluid and easy to look at.
    I'm always surprised that almost every library dealing with graphics gets advertised as "high performant" while IMO such a statement is completely pointless without the specific usecase. Qwt offers several optimizations ( or workarounds for Qt bottlenecks ) and algorithms, but it's up to you to combine them to a performant plot application. ( F.e you can ruin any performance of a plot widget by using 10000 markers instead of a curve with 10000 points ).

    If the buffering of QwtPlot makes an application more or less fluid depends on the type of plot you want to implement. But in data intensive applications its more about the question how to reduce what needs to be painted - the performance of painting itself is less important. How to do this depends on your requirements and the characteristics of your data - often you end with a combination of point weeding and polygon clipping. Check the archive of this forum for "levels of detail".

    Uwe

    PS: Note that Qwt from SVN trunk reintroduces several optimizations that were gone in Qwt 6.0.

Similar Threads

  1. QwtPlot - multiple axis
    By MukundanAR in forum Qwt
    Replies: 1
    Last Post: 7th March 2012, 08:53
  2. QwtPlot - multiple axis
    By MukundanAR in forum Newbie
    Replies: 0
    Last Post: 6th March 2012, 12:50
  3. QwtPlot legend with axis
    By desantossierra in forum Qwt
    Replies: 5
    Last Post: 20th January 2012, 15:05
  4. QwtPlot fixed X-axis display
    By micc13 in forum Qwt
    Replies: 2
    Last Post: 3rd December 2010, 13:28
  5. QwtPlot axis decmials/notation
    By dfirestone in forum Qwt
    Replies: 1
    Last Post: 1st May 2009, 11:42

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.