Results 1 to 13 of 13

Thread: The datas in ticks can't display correctly

  1. #1
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question The datas in ticks can't display correctly

    The ticks I print from function buildMajorTicks( ) is (-1e+18, -3.16228e+11, -100000, 31.6228, 1e+08, 3.16228e+14, 1e+21),
    but my axis can't display correctly.What the problem is?
    qwt_scale.jpg

  2. #2
    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: The datas in ticks can't display correctly

    Are talking about QwtLinearScaleEngine::buildMajorTicks() from Qwt 6.1 - if yes the parameters from your posting doesn't match.
    And to be able to check your situation it would help to know the parameters of QwtLinearScaleEngine::divideScale instead.

    Uwe

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

    yellowfisher (25th February 2016)

  4. #3
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    no, i build a class which derived from QwtScaleEngine to draw sign(x)*log(|x|). datalist
    Qt Code:
    1. (-1e+18, -3.16228e+11, -100000, 31.6228, 1e+08, 3.16228e+14, 1e+21)
    To copy to clipboard, switch view to plain text mode 
    is build from MyScaleEngine::buildMajorTicks().
    in my transform class ,i set boundaries as
    Qt Code:
    1. qBound(-LOG_MAX, value, LOG_MAX)
    To copy to clipboard, switch view to plain text mode 
    .


    Added after 1 45 minutes:


    Here is the code i write in myBuildMajorTicks() function.
    Qt Code:
    1. QList<double> DocPlot::PlotSignScaleEngine::buildMajorTicks(
    2. const QwtInterval& interval, double stepSize) const
    3. {
    4. qDebug()<<"in function buildMajorTicks"<<endl;
    5.  
    6. double minValue = interval.minValue();
    7. double maxValue = interval.maxValue();
    8.  
    9. double width = qwtLogInterval(base(), interval).normalized().width();
    10. if(minValue * maxValue < 0.0)
    11. width = qwtLogInterval(base(), QwtInterval(1, maxValue)).normalized().width() +
    12. qwtLogInterval(base(), QwtInterval(minValue, 1)).normalized().width();
    13.  
    14. qDebug()<<"width = "<<width<<" stepSize = "<<stepSize<<endl;
    15.  
    16. int numTicks = qRound( width / stepSize ) + 1;
    17.  
    18. if ( numTicks > 10 )
    19. numTicks = 10;
    20.  
    21. qDebug()<<"numTicks = "<<numTicks<<endl;
    22.  
    23. const double lxmin = ::log( qAbs(interval.minValue()) );
    24.  
    25. const double lxmax = ::log( qAbs(interval.maxValue()) );
    26.  
    27. const double lstep = (lxmax-lxmin) / double(numTicks-1);
    28. qDebug()<<"lxmin = "<<lxmin<<" lxmax = "<<lxmax<<endl;
    29.  
    30. QList<double> ticks;
    31.  
    32. ticks += interval.minValue();
    33.  
    34. if(maxValue < 0.0)
    35. {
    36. for(int i = 1; i < numTicks - 1; i++)
    37. ticks += -qExp(lxmin + double(i) * lstep);
    38. }
    39. else
    40. {
    41. if(minValue * maxValue < 0.0)
    42. {
    43. qDebug()<<"1111111111111111111111111111111111111"<<endl;
    44. int number = qRound(numTicks * (lxmin / (lxmin + lxmax)));
    45. qDebug()<<"number = "<<number<<endl;
    46. double blstep = (0 - lxmin) / double(number - 1);
    47. qDebug()<<"blstep = "<<blstep<<endl;
    48. double glstep = (lxmax - 1) / double(numTicks - number - 1);
    49. qDebug()<<"glstep = "<<glstep<<endl;
    50. int j = 1;
    51. for (int i = 1; i < numTicks - 1; i++)
    52. {
    53. if((lxmin + blstep * double(i)) > 0.0)
    54. {
    55. j++;
    56. ticks += -qExp(lxmin + double(i) * blstep);
    57. }
    58. else
    59. ticks += qExp((double(i) - j - 1) * glstep);
    60. }
    61. }
    62. else
    63. for(int i = 1; i < numTicks - 1; i++)
    64. ticks += qExp(lxmin + double(i) * lstep);
    65. }
    66.  
    67. // for(int i = 1; i < numTicks - 1; i++)
    68. // ticks += qExp(lxmin + double(i) * lstep);
    69.  
    70. ticks += interval.maxValue();
    71.  
    72. qDebug()<<"ticks = "<<ticks<<endl;
    73.  
    74. return ticks;
    75. }
    To copy to clipboard, switch view to plain text mode 
    It works fine while the log aixs's data is all negative or all positive.
    The attachment file is the curve data I want to plot.
    Attached Files Attached Files
    Last edited by yellowfisher; 25th February 2016 at 09:01.

  5. #4
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    The parameters I pass to divideScale() are: x1=-1e+18, x2=1e+21, maxMajorSteps=8, maxMinorSteps=5, stepSize=1.
    And this is my align function:
    Qt Code:
    1. QwtInterval intv = qwtLogInterval(base(), interval);
    2.  
    3. if (intv.minValue() > intv.maxValue())
    4. intv = QwtInterval(intv.maxValue(), intv.minValue());
    5.  
    6. double x1 = QwtScaleArithmetic::floorEps(intv.minValue(), stepSize);
    7. if(interval.minValue() * interval.maxValue() < 0.0)
    8. x1 = QwtScaleArithmetic::ceilEps(intv.minValue(), stepSize);
    9. if(qwtFuzzyCompare(interval.minValue(), x1, stepSize) == 0)
    10. x1 = interval.minValue();
    11.  
    12. double x2 = QwtScaleArithmetic::ceilEps(intv.maxValue(), stepSize);
    13. if(qwtFuzzyCompare(interval.maxValue(), x2, stepSize) == 0)
    14. x2 = interval.maxValue();
    15.  
    16. return qwtPowInterval(base(), QwtInterval(x1, x2), interval);
    To copy to clipboard, switch view to plain text mode 

    I also overwrited function qwtPowInterval() as:
    Qt Code:
    1. qwtPowInterval(double base, const QwtInterval& interval, const QwtInterval& interval_ref)
    2. {
    3. double minValue = interval_ref.minValue();
    4. double maxValue = interval_ref.maxValue();
    5. QwtInterval intv;
    6.  
    7. if (maxValue < 0.0)
    8. {
    9. intv = QwtInterval(-qPow(base, interval.minValue()), -qPow(base, interval.maxValue()));
    10. if(intv.maxValue() < intv.minValue())
    11. return QwtInterval(intv.maxValue(), intv.minValue());
    12. else
    13. return intv;
    14. }
    15.  
    16. else if(maxValue == 0.0)
    17. return QwtInterval(-qPow(base, interval.minValue()), -LOG_MIN);
    18.  
    19. else
    20. {
    21. if(minValue < 0.0)
    22. return QwtInterval(-qPow(base, interval.minValue()), qPow(base, interval.maxValue()));
    23.  
    24. else if (minValue == 0.0)
    25. return QwtInterval(LOG_MIN, qPow(base, interval.maxValue()));
    26.  
    27. else
    28. return QwtInterval(qPow(base, interval.minValue()), qPow(base, interval.maxValue()));
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 
    The interval_ref i pass to qwtPowInterval is QwtInterval(-1e+18, 1e+21).
    Last edited by yellowfisher; 26th February 2016 at 02:19.

  6. #5
    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: The datas in ticks can't display correctly

    O.k. so you want to implement your own type of scale engine and we are not talking about Qwt code ?

    You wrote you want to implement something like "sign(x)*log(|x|)", what should be an easy one with QwtLogarithmicScaleEngine as long as your scales are positive or negative.
    As soon as you have a scale with a range, that includes the 0, you have the problem, that you need to define a small interval with a non logarithmic transformation to work around the 0.

    F.e. you could use a linear or transformation for the range [-1, 1] - or maybe using a power based one. ( see the scaleengine example ).

    But without knowing, what type of scale + transformation you want to have ...

    Uwe

  7. #6
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    The scale transformation is my problem, I don't know how to write a transformation to transforme negative log scales.

  8. #7
    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: The datas in ticks can't display correctly

    No your problem is that you have to cross the 0, when having a transformation that goes from -LOG_MAX, value, LOG_MAX.

    Uwe

  9. #8
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    I still don't know how to cross the 0, do you mean I should split (-1e+18, 1e+21) into 3 intervals like : (-LOG_MAX, -LOG_MIN), (-LOG_MIN, LOG_MIN), (LOG_MIN, LOG_MAX)?
    If so, which function or class i need to work on?
    Last edited by yellowfisher; 29th February 2016 at 03:30.

  10. #9
    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: The datas in ticks can't display correctly

    Quote Originally Posted by yellowfisher View Post
    do you mean I should split (-1e+18, 1e+21) into 3 intervals like : (-LOG_MAX, -LOG_MIN), (-LOG_MIN, LOG_MIN), (LOG_MIN, LOG_MAX)?
    Yes of course - not because of Qwt, but because of the underlying maths that are needed for a transformation.

    If so, which function or class i need to work on?
    First of all you need to define something bijective to map between plot and widget coordinates. Using a linear or power based formula might be candidates for the segment around the 0.
    [-LOG_MIN, LOG_MIN] is probably too small for this segment, better start with [ -1.0, 1.0 ] - or something that makes sense, in your context, when you have a curve that passes 0.

    Start with checking the code of qwt_scale_map.[h|cpp] and qwt_transform.[h|cpp]. Then you will understand the code of the scaleengine example, where you f.e find the At400 transformation. Its implementation is also splitting into 3 intervals ( linear/pow/linear ) and might serve as a starting point for you.

    I recommend to simply use a QwtLinearScaleEngine in the beginning - maybe even assigning the ticks manually like in the example. Once you have the transformation running we can see how to tweak the logarithmic engine to calculate useful ticks positions.

    Uwe

  11. #10
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    Thanks for your reply.
    I have checked scaleengine example in qwt-6.1.1/palyground, i wrote my MyLogTransformation::transform() like this:
    Qt Code:
    1. double transform(double value) const
    2. {
    3. if(value >= 1)
    4. return ::log(value - 1);
    5. if(value <= -1)
    6. return -::log(qAbs(value) + 1);
    7. return value;
    8. }
    To copy to clipboard, switch view to plain text mode 
    And it doesn't work. I have no idea of how to write this function. Can you give me more recommendation?

  12. #11
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    Another problem is that my data is loaded from files, there has possibilities that all values are in interval like [-1, 0.5]. Maybe I should pass the maximum value and minimum value in my data as parameters to transform( ), but how to get plot data from QwtPlot?

  13. #12
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    for now i can draw curve correctly. but the first tick in MajorTicks still can't display correctly.qwt_bug.png
    I want to know what makes this happened.

  14. #13
    Join Date
    Sep 2015
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The datas in ticks can't display correctly

    Finally it works.qwt_signeLog_scale.jpg
    But there still has a problem with plot. There has no variable in [-2e16, 2e16] in my data sheet, so I want it plot like this:example.png
    The interval [-2e16, 2e16] just takes a little scale of axis so that there has more places for meaningful variables.
    Attached Images Attached Images

Similar Threads

  1. Replies: 1
    Last Post: 14th April 2014, 06:27
  2. Replies: 14
    Last Post: 30th October 2012, 15:45
  3. Display german umlauts did not work correctly
    By HeReSY in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2011, 22:43
  4. QWebView doesn't display correctly unicode
    By binaural in forum Qt for Embedded and Mobile
    Replies: 16
    Last Post: 3rd September 2010, 08:24
  5. QTableView does not display time string correctly
    By ad5xj in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2007, 20:35

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.