Menu

#2085 logarithmic dataset with 2D heatmap

None
closed-not-a-bug
nobody
None
2021-02-19
2018-11-11
Anonymous
No

Gnuplot version: 5.2 patchlevel 5
platform: Linux 4.16.13-041613-generic x86_64 (Linux Mint 18.3)

Hi,

using a 2D heatmap via 'plot ... with image' gives a wrong output if the data are not distributed with a linear binning. It is unclear to me if this is a know effect or a bug.

My input data have the following structure:
1.000000E+00 1 3.720141E+00
1.000000E+00 2 2.098816E+01
....
1.000000E+00 99 2.317764E+03
1.000000E+00 100 2.388149E+03
1.006938E+00 1 3.663303E+00
1.006938E+00 2 2.067914E+01
.............
9.852816E+02 99 2.037077E-03
9.852816E+02 100 2.211063E-03
9.921171E+02 1 1.242277E-18
9.921171E+02 2 3.228117E-16
...
9.921171E+02 99 1.962383E-03
9.921171E+02 100 2.131414E-03

i.e. the x-values are calculated with a log-binning, the y-values are in lin-style.

Plotting the logarithmic this data set with a linear x-scale and changing the scale (by hand -> Incscape) to a logarithmic scaling gives the correct result.

4 Attachments

Discussion

  • Daniel Maier

    Daniel Maier - 2018-11-11

    Uh, typo: I meant "Plotting this data set with a linear x-scale and changing the scale (by hand -> Incscape) to a logarithmic scaling gives the correct result."

    DataLinBin_linscaleX.png and DataLinBin_logscaleX.png show a correct result.
    DataLogBin_linscaleX.png shows the same image as DataLinBin_logscaleX.png but with a wrong x-axis.
    Changing the x-axis scaling to log-style changes the data image -> DataLogBin_logscaleX.png.

    Is there a way to change only the X-axis, but not the data? This wouldn't be a clean solution, but a quick and dirty work around...

     
  • Ethan Merritt

    Ethan Merritt - 2019-05-21

    This one seems to have slipped through a crack. I don't remember ever looking at it, but now that I do look at it I don't understand what exactly is being tried. In particular I don't understand what "binning" means in the context of "plot with image". Can you please attach a script and if necessary an associated data file that demonstrate the failure?

     
  • Ethan Merritt

    Ethan Merritt - 2019-12-04
    • status: open --> closed
    • Group: -->
    • Priority: -->
     
  • Alexander Brock

    Alexander Brock - 2021-01-31

    I found the same problem and made the simplest example I could think of.
    If you look at the file "2d-exp.data" you'll see that the x-values are 10, 100, 1'000, 10'000 and 100'000
    but in the plot the first bin occupies roughly [10:10'000], the second bin [10k:40k], the third bin [40k:60k], the fourth bin [60k:80k] and the last bin [80k:105k]

    I verified that with gnuplot 5.2 patchlevel 8 on Debian Bullseye (5.4.1+dfsg1-1) and with the latest git version (40a9029b292812cd5a69134b140841746767a93b)

     
    • Ethan Merritt

      Ethan Merritt - 2021-01-31

      I think the simplest answer is that "with image" is not an appropriate plot style for data in this form. The very first sentence in the documentation for with image notes that it assumes a uniformly sampled grid.

      gnuplot> help with image
      
       The `image`, `rgbimage`, and `rgbalpha` plotting styles all project a
       uniformly sampled grid of data values onto a plane  in either 2D or 3D.
       The input data may be an actual bitmapped image, perhaps converted from a
       standard format such as PNG, or a simple array of numerical values.
      

      Using with pm3d would come closer to your intent:

      set yrange [0 : 6]
      set xrange [1 : 1000000]
      set logscale x
      set view map
      splot "2d-exp.data" u 1:2:3 with pm3d
      

      However there is a fundamental difference between the component pixels of an image plot and a pm3d plot. The former creates a uniformly sized box centered at each data point (which is why the data must be equally spaced). One pixel is created for each data point. The latter treats the coordinates as defining the corners of a set of boxes, possibly of varying size. Because each box needs both a low and a high coordinate in each direction, NxM data points produce (N-1)x(M-1) boxes.

      For this particular case you could manipulate the data to restore uniform spacing and then artificially label the plot to show an exponential range. I cannot say whether the result accurately presents what you need to show:

      set xrange [1.15129:12.6642]
      set x2range [exp(1.15129):exp(12.6642)]
      set x2tics
      unset xtics
      plot "2d-exp.data" u (log($1)):2:3 with image
      

       
      👍
      1

      Last edit: Ethan Merritt 2021-01-31
      • Alexander Brock

        Alexander Brock - 2021-02-01

        Thank you, that was very helpful. I wanted to report that pm3d has the disadvantage (compared to image) that if I set the xrange to start or end in the middle of a "pixel" that rectangle doesn't get plotted but it is fixed in the git version I tried.

        Therefore all my current problems with gnuplot have been solved :-)

        Regarding the behavior of plotting with image I think it would be nice if there was a warning for non-regular spaced grids.

         
  • Alexander Brock

    Alexander Brock - 2021-01-31
    • status: closed --> open
     
  • Alexander Brock

    Alexander Brock - 2021-01-31

    I made more examples showcasing what I expected:

    First, a 1D example

    • 1d.gpl plots some data into 1d.png (as expected)
    • 1d-log.gpl set logscale x and plots with using "10 to the power of $1":2, so the values on the x-axis change but the graphical appeareance of the curve stays exactly the same. This also works as expected.

    Now, the 2D example:

    • 2d.gpl plots data as expected.
    • 2d-log-x.gpl basically does the same thing as 1d-log.gpl and therefore the result should look the same as 2d.png except for the labels of the x-axis

    I manually labeled the x-axis (2d-workaround.gpl/png) to show the plot I would have expected.

     
  • Ethan Merritt

    Ethan Merritt - 2021-02-19
    • status: open --> closed-not-a-bug
     

Log in to post a comment.

MongoDB Logo MongoDB