No announcement yet.

simple scatterplot

  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Hi Mike,

    I hope that my eagerness to help wasn't in a way impolite. I am very grateful of all that I can learn every day from this forum, and this is one of the very rare cases where I thought I had some experiences to share. Specially, since like you, I used to program in TB. Anyway to trump Dave is absolutely out of my capabilities, and he is very, very hi in my regards.

    The codes I posted can't deal with negative numbers, but that can be quite easily corrected. Please let me know if you have any other comment or question about it.

    Best regards,
    Last edited by Manuel Valdes; 17 Feb 2012, 08:35 PM.


    • #22
      Hi Mike,
      Hope your wife is coping OK?

      I haven't made as much progress on the scaling / axes algo stuff as I would have liked yet. (I'm afraid I really don't deserve Manuel's high esteem ).

      I did google my way to a site that discussed some possible solutions though and cobled together this test code. It shows some promise..
      #DIM ALL
       LOCAL xmin, xmax, xRange AS SINGLE
       LOCAL Steps AS LONG, StepSize AS SINGLE
        xmin = 1.4                  ' change to test
        xmax = 2.0                  '
        Steps = 10                 '
        xRange = xmax - xmin
        ? "xmin" xmin "xmax" xmax "xRange" xRange "Steps" Steps
        ' "Pretty step" algo
        CalculateStepSize(xRange, Steps) TO StepSize
        ? "StepSize" StepSize
        ' Adjust _min and _max
        xmin = StepSize * Int(xmin/StepSize)         ' -0.5 ?
        xmax = StepSize * ceil(xmax/StepSize)
        ? "Adjusted xmin" xmin "xmax" xmax
        ? "Actual steps " (xmax - xmin)/StepSize
      FUNCTION CalculateStepSize(Range AS SINGLE, Steps AS LONG) AS SINGLE
       LOCAL tempstep AS SINGLE
       LOCAL mag, magPow AS SINGLE, magMsd AS LONG
        ' calculate an initial guess at step size
        tempStep = range/Steps    : ? "tempstep" tempStep
        ' get the magnitude of the step size
        mag = FIX(LOG10(tempStep))  : ? "mag" mag
        magPow = 10^mag              : ? "magPow" magPow
        ' calculate most significant digit OF the NEW STEP SIZE
        magMsd = int((tempStep/magPow) + 0.5)  : ? "magMsd" magMsd
        ' promote the MSD TO either 1, 2, OR 5
          IF (magMsd > 5.0) THEN
            magMsd = 10.0
          ELSEIF (magMsd > 2.0) THEN
            magMsd = 5.0
          ELSEIF (magMsd > 1.0) THEN
            magMsd = 2.0
          END IF
        ? "magMsd*magPow" magMsd*magPow
         IF magMsd*magPow < 1 THEN Decr Steps : GOTO ReStart
       FUNCTION = magMsd*magPow
      Perhaps a version of this method of might suffice to configure the two axes?

      Give it a spin and see what you think.
      Rgds, Dave


      • #23
        Hi Dave, Hi Mike,

        Attached a simpler, bare-bones version, which I hope will respond in a better way to Mike's purposes.

        The "POINTS.CSV" file was created with 100 pairs of values, using the RND function, except that I included three special point to control the accuracy of the deployment (-100,-100; 0,0 and 100,100).

        I know this subject is in a way tricky, since I have been programming this type of stuff for the last 37 years.

        Best regards,
        Attached Files
        Last edited by Manuel Valdes; 20 Feb 2012, 05:29 AM.


        • #24
          Hi Manuel,

          Thanks for the 'bare-bones' version I shall be picking over it for more goodies!

          I've done a bit more with the CalculateStepSize function and incorporated it in this (final?) example.
          It seems to work quite well with the data files in the zip below.
          The sample data includes a modified version of your latest POINTS.CSV data. I removed the three special points and the function comes up with the same axes automagically!
          Attached Files
          Rgds, Dave


          • #25
            Hi Dave

            Many thanks, now I have something good to study a fresh view of the subject. For starter I like the idea of the 0-0 axes, and I'm thinking whether to superimpose them using a different colour, or to start the grid lines from them going up and down, left and right.

            As I am a lousy typist, I use this small code to produce my testing data files, playing with the random algorithm to get some effects:

            #COMPILE EXE
            '#DIM ALL
             PRINT #1, "X-Value,Y-Value"
             FOR I%=1 TO 400
              PRINT #1,RND(-IV1&,IV1&)/100;CHR$(44);RND(-IV2&,IV2&)/100
             CLOSE 1
            END FUNCTION
            Best regards,
            Last edited by Manuel Valdes; 20 Feb 2012, 05:31 PM.


            • #26
              Dave: GW Plot is just about exactly what I was trying to achieve - thanks, I've learned a lot. I'll be able to incorporate those ideas into my main program.

              Manuel: Your program was too sophisticated for my simple needs for this particular job, but the ideas in it will be of great help to me when writing future programs. And I like your random data generator - most useful for testing. Is there any significance in the number 38?

              Thanks again, guys.


              • #27
                Hi Mike,

                Good!. I'm also learning a lot from Dave's code. The number 38 doesn't have special meaning, except that it's 15000/400 rounded to the closest integer. The idea was to get the RND ranges closer and closer to 0, so as to concentrate the points around that value.

                Best regards,