sciapp / gr

GR framework: a graphics library for visualisation applications
Other
328 stars 54 forks source link

GRM - Line - right limit is probably too big #116

Closed mantielero closed 4 years ago

mantielero commented 4 years ago

It looks like the rigth limit is not properly calculated. You can see the result here. This also appears to happen with the scatter plot. I understand that this is because they share the same function.

IngoMeyer441 commented 4 years ago

A similar C example

static void test_line(void)
{
  double x[40], y[40];
  int n = sizeof(x) / sizeof(x[0]);
  grm_args_t *args;
  int i;

  printf("filling argument container...\n");

  for (i = 0; i < n; ++i)
    {
      x[i] = -2.0 + 4.0 * ((double)i / (n - 1));
      y[i] = x[i] * x[i] * x[i] + x[i] * x[i] + x[i];
    }

  args = grm_args_new();
  grm_args_push(args, "x", "nD", n, x);
  grm_args_push(args, "y", "nD", n, y);
  grm_args_push(args, "kind", "s", "line");

  printf("plotting data...\n");

  grm_plot(args);

  printf("Press any key to continue...\n");
  getchar();

  grm_args_delete(args);
}

produces (on my system)

image

If you still get a wrong behavior with GR 0.49.0, could you try to create a debug build and send logging output? You can compile a debug version of GR with:

git clone https://github.com/sciapp/gr.git
cd gr
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/gr \
      -DCMAKE_BUILD_TYPE=Debug \
      -DGR_USE_BUNDLED_LIBRARIES=OFF \
      -S . \
      -B build
cmake --build build
cmake --install build
JonasClever commented 4 years ago

It looks like the rigth limit is not properly calculated. You can see the result here. This also appears to happen with the scatter plot. I understand that this is because they share the same function.

I tested your examples and it seems like Nim is transmitting the data incorrectly. Here is the JSON which is internally generated by GRM:

{
   "plots":[
      {
         "array_index":0,
         "in_use":1,
         "subplots":[
            {
               "array_index":0,
               "series":[
                  {
                     "array_index":0,
                     "x":[
                        -2.,
                        -1.8999999999999999,
                        -1.7999999999999998,
                        -1.6999999999999997,
                        -1.5999999999999996,
                        -1.4999999999999996,
                        -1.3999999999999995,
                        -1.2999999999999994,
                        -1.1999999999999993,
                        -1.0999999999999992,
                        -0.99999999999999922,
                        -0.89999999999999925,
                        -0.79999999999999927,
                        -0.69999999999999929,
                        -0.59999999999999931,
                        -0.49999999999999933,
                        -0.39999999999999936,
                        -0.29999999999999938,
                        -0.19999999999999937,
                        -0.099999999999999367,
                        6.3837823915946501e-16,
                        0.10000000000000064,
                        0.20000000000000065,
                        0.30000000000000066,
                        0.40000000000000069,
                        0.50000000000000067,
                        0.60000000000000064,
                        0.70000000000000062,
                        0.8000000000000006,
                        0.90000000000000058,
                        1.0000000000000007,
                        1.1000000000000008,
                        1.2000000000000008,
                        1.3000000000000009,
                        1.400000000000001,
                        1.5000000000000011,
                        1.6000000000000012,
                        1.7000000000000013,
                        1.8000000000000014,
                        1.9000000000000015,
                        2.0000000000000013
                     ],
                     "y":[
                        -6.,
                        -5.1489999999999991,
                        -4.3919999999999986,
                        -3.7229999999999981,
                        -3.1359999999999983,
                        -2.6249999999999978,
                        -2.1839999999999975,
                        -1.8069999999999979,
                        -1.487999999999998,
                        -1.2209999999999981,
                        -0.99999999999999845,
                        -0.81899999999999873,
                        -0.67199999999999904,
                        -0.55299999999999927,
                        -0.45599999999999941,
                        -0.3749999999999995,
                        -0.30399999999999955,
                        -0.2369999999999996,
                        -0.16799999999999954,
                        -0.09099999999999947,
                        6.3837823915946541e-16,
                        0.11100000000000079,
                        0.248000000000001,
                        0.41700000000000126,
                        0.62400000000000155,
                        0.87500000000000178,
                        1.1760000000000019,
                        1.5330000000000024,
                        1.9520000000000031,
                        2.4390000000000027,
                        3.0000000000000044,
                        3.6410000000000053,
                        4.3680000000000065,
                        5.1870000000000074,
                        6.1040000000000099,
                        7.1250000000000124,
                        8.2560000000000144,
                        9.5030000000000179,
                        10.872000000000019,
                        12.369000000000025,
                        14.000000000000023
                     ],
                     "spec":""
                  }
               ],
               "kind":"line",
               "subplot":[
                  0.,
                  1.,
                  0.,
                  1.
               ],
               "xlog":0,
               "ylog":0,
               "zlog":0,
               "xflip":0,
               "yflip":0,
               "zflip":0,
               "adjust_xlim":1,
               "adjust_ylim":1,
               "adjust_zlim":1,
               "colormap":44,
               "font":232,
               "font_precision":3,
               "rotation":40,
               "tilt":70,
               "keep_aspect_ratio":0
            }
         ],
         "clear":1,
         "update":1,
         "size":[
            600.,
            450.
         ],
         "wswindow":[
            0.,
            1.,
            0.,
            0.7511811023622047
         ],
         "wsviewport":[
            0.,
            0.15875,
            0.,
            0.11924999999999999
         ],
         "previous_pixel_size":[
            600,
            450
         ]
      }
   ],
   "append_plots":0
}

And because the highest x value is 2.0000000000000013, GRM tries to calculate a window in which all data is visible and a nice round number (in this case 3) is chosen as the most right boundary. The same applies for the y value which is 14.000000000000023 which becomes 15. Since our Julia and Python wrappers do not experience this problem it seems to be an issue with Nim.

IngoMeyer441 commented 4 years ago

Commit f8d83a06b3092e017bf9c8b31cc32977c2aeb76b adds an epsilon to the gr_adjustlimits function and should solve the rounding problems. If you want to test the new code, you can switch to the development version of GR by installing gr-framework-git from the AUR.

mantielero commented 4 years ago

I tested it and it works