Announcement

Collapse
No announcement yet.

Chart Tic Mark Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Chart Tic Mark Values

    I spent just about enough time on this one. Now I need some help.

    I need to calculate tic mark values for a y axis of an x,y graph given Min/Max Values.

    The Tic Mark values should be a power of 10.

    Example #1: Given a MinVal of -12.56 and a Max Value of 4567 the MinTic Mark will be -1000 and the MaxTic Mark is 5000.

    Example #2: MinVal -4567 MaxVal 7.7 -> MinTic Mark = -5000 and MaxTic Mark = 1000

    Example #3: MinVal -.756 MaxVal .789 -> MinTic -1 MaxTic 1.

    The Min/Max Values may be anything in the range of doubles.

    Thank You.

    James
    Attached Files

  • #2
    Powers of 10 or Thousands?
    Example #1: Given a MinVal of -12.56 and a Max Value of 4567 the MinTic Mark will be -1000 and the MaxTic Mark is 5000.
    If power of 10, then a min of -100 is sufficient.

    In any event, just take the LOG10 of the absolute value of min and max. The integer portion of that (plus 1?) will be the number of decimal digits BEFORE the decimal point. If 1000's use MOD 3 and add one if value is not exact If power of 10, you have the number of integer scale units you need.

    I think there's probably a way to do it using INT + CEIL + MIN/MAX, too.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thanks Michael. My math really sucks.
      Actually it is the power of the largest abs value. I'm having a hard time explaining it. I want this to work for Example #3 also. I have it almost working using brute force but I started loosing it so I thought I'd try here for some different directions or ideas.

      I'll clean up the source and post it later, but am still open for ideas.

      James

      Comment


      • #4
        James,
        assuming you want integers only, try this:
        Code:
        'PBCC5.0 program
        #COMPILE  EXE
        #DIM      ALL
          
        FUNCTION PBMAIN () AS LONG
        LOCAL MinVal,MaxVal,MinTicMark,MaxTicMark,PowerOfTen AS DOUBLE
        
        MinVal=-12.56
        MaxVal=4567
        
        'MinVal=-4567
        'MaxVal=7.7
                    
        'MinVal=-.756
        'MaxVal=.789
        
        
        PowerOfTen = MAX(1,10^INT(LOG10(MAX(ABS(MinVal),ABS(MaxVal))))) 'the MAX(1,x) is to stop the function giving steps of <1
        
        MaxTicMark = CEIL(MaxVal/PowerOfTen) * PowerOfTen
        MinTicMark = INT(MinVal/PowerOfTen) * PowerOfTen
        
        PRINT "MinTicMark=";MinTicMark,"MaxTicMark=";MaxTicMark
        WAITKEY$
        
        END FUNCTION
        Paul.

        Comment


        • #5
          JC,
          The post alone got me curious just what you are up to????
          I can see other possible applications if you get it working
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment


          • #6
            Is this what you are looking for ?

            Some time ago i posted in the Source code forum a simple Sci/eng plotting routine http://www.powerbasic.com/support/pb...ad.php?t=37531 that contains precisely the algorithms you are looking for,
            maybe this can help you.

            Arie Verheul

            Comment


            • #7
              Paul,
              Almost! My associate pointed out a failure which probably was more a poor description by me, being as math challenged as I am.
              Code:
              MinVal = -.0756 -> -1 
              MaxVal = .0789 ->  +1
              Should be -0.1 and +0.1 respectively.

              James

              Comment


              • #8
                James,
                are you sure?
                I added the "MAX(1, ComplicatedBit) to stop the scale going below 1 as you suggested was needed in example 3 but I don't think that's what you really wanted (hence the comment I put in the code).
                In practice, I think you want the following:

                Example #1: Given a MinVal of -12.56 and a Max Value of 4567 the MinTic Mark will be -1000 and the MaxTic Mark is 5000.

                Example #2: MinVal -4567 MaxVal 7.7 -> MinTic Mark = -5000 and MaxTic Mark = 1000

                Example #3: MinVal -.756 MaxVal .789 -> MinTic -0.8 MaxTic 0.8.

                Example #4: MinVal = -.0756 MaxVal = .0789 -> MinTic -0.08 MaxTic 0.08.



                To have 1 or 0.1 for the last two examples doesn't make sense, the scale graduation should be 0.1 and 0.01 and there are 8 tic marks to be shown.
                To do what you suggest and have a scale graduation of 1 and 0.1 will mean there is only a single tic for any value smaller than 1 and that tic will be at the limit of the graph so it won't look graduated at all.

                Just change my code by removing the MAX(1, ...) and see what it gives.

                Paul.
                Code:
                PowerOfTen = 10^INT(LOG10(MAX(ABS(MinVal),ABS(MaxVal))))
                
                MaxTicMark = CEIL(MaxVal/PowerOfTen) * PowerOfTen
                MinTicMark = INT(MinVal/PowerOfTen) * PowerOfTen

                Comment


                • #9
                  Paul,
                  Removing MAX gives -.08 and .08. He wants -0.1 and +0.1 respectively.?
                  I'll let him chime in when he gets up. He's a West Coaster so it will be awhile.
                  Thanks for your input. Much appreciated.

                  James

                  Comment


                  • #10
                    Arie,
                    I was going to take a look at your code but couldn't get out of the program when run so .....

                    James

                    Comment


                    • #11
                      James,
                      consider your example 1.
                      Example #1: Given a MinVal of -12.56 and a Max Value of 4567 the MinTic Mark will be -1000 and the MaxTic Mark is 5000.
                      The tic-spacing is 1000 and the MaxTic is 5000. It is one tic above the MaxVal.

                      Now consider the 4th case:
                      Example #4: MinVal = -.0756 MaxVal = .0789 -> MinTic -0.08 MaxTic 0.08.
                      Here the tic spacing is 0.01 and the MaxTic will be 0.08, i.e. one tic spacing above your MaxVal.

                      If, in example 4, you wanted MaxTic to be 0.1 then the equivalent in example 1 would be to have MaxTic at 10,000, not 5,000.


                      Perhaps it might help you think about it if you used the same figures but reduced the scale so take example 1 and divide all the values by 100,000. This should give the exact same graph as the original example 1 except the numbers along the y-axis will be 100,000 times smaller. So, you'd expect "tic-spacing of 1000 and MaxTic of 5000" to become "tic-spacing of 0.01 and MaxTic of 0.05".
                      But in your 4th example your suggestion is that the values should be tic-spacing of 0.01 and MaxTic of 0.1" which is clearly inconsistent.

                      Paul.

                      Comment


                      • #12
                        My understanding is these plots are to be used primarily to see if a value (or group of values) is out of place before performing some lengthy calculations. It is possible to have values within the scope of Min/Max Input parameters but out of place when it comes to a particular calculation. So I'm not sure if consistency is really factor?

                        James

                        Comment


                        • #13
                          Paul,
                          I received confirmation that the removal of MAX will produce the wanted Min/Max.
                          Thank you very much for your code and expertise.

                          James

                          Comment

                          Working...
                          X