0

I would like to be able to make a graph as produced by the code shown below (but using logarithmic axes). I have a 2D matrix containing the data and I know the separation positions between one cell and the other (equispaced if viewed in logarithmic scale). The code that I report below simulates what I would like obtain but it use Hist_2D and therefore I do not think it is usable in my case.

An example of my data:

data is a Matrix 9*9

   data [0.000     0.000     0.000     0.000     0.000     0.000     0.000     0.000     0.000
0.429     0.143     0.000     0.000     0.048     0.000     0.000     0.000     0.000
0.857     0.810     0.667     0.429     0.429     0.286     0.190     0.286     0.143
0.952     0.952     0.905     0.857     0.857     0.905     0.857     0.762     0.810
1.000     1.000     0.952     0.952     0.952     0.952     0.952     0.952     1.000
1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000
1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000
1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000
1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000     1.000]

x e y are two vector of length 10

x [0.189036 0.484322 0.779609 1.07489 1.37018 1.66547 1.96075 2.25604 2.55133]

y [ -1.06208 -0.584192 -0.106299 0.371593 0.849485 1.32738 1.80527 2.28316 2.76105]

code

PRO Plot2
x = cgScaleVector(Randomn(-3L, 100000)*3., -10, 10)
y = cgScaleVector(Randomn(-5L, 100000)*10., 0, 100)

xrange = [Min(x), Max(x)]
yrange = [Min(y), Max(y)]
xbinsize = 0.25
ybinsize = 3.00
cgDisplay
density = Hist_2D(x, y, Min1=xrange[0], Max1=xrange[1], Bin1=xbinsize, Min2=yrange[0], Max2=yrange[1], Bin2=ybinsize)   

maxDensity = Ceil(Max(density)/1e2) * 1e2
scaledDensity = BytScl(density, Min=0, Max=maxDensity)

cgLoadCT, 33
TVLCT, cgColor('gray', /Triple), 0
TVLCT, r, g, b, /Get
palette = [ [r], [g], [b] ]

cgImage, scaledDensity, XRange=xrange, YRange=yrange, /Axes, Palette=palette, $
  XTitle='Concentration of X', YTitle='Concentration of Y', $
  Position=[0.125, 0.125, 0.9, 0.8]

thick = (!D.Name EQ 'PS') ? 6 : 2
cgContour, density, LEVELS=maxDensity*[0.25, 0.5, 0.75], /OnImage, $
   C_Colors=['Tan','Tan', 'Brown'], C_Annotation=['Low', 'Avg', 'High'], $
   C_Thick=thick, C_CharThick=thick


cgColorbar, Position=[0.125, 0.875, 0.9, 0.925], Title='Density', $
   Range=[0, maxDensity], NColors=254, Bottom=1, OOB_Low='gray', $
   TLocation='Top'
END ;*****************************************************************


Plot2

END

Thanks for your help!

Neuron
  • 5,141
  • 5
  • 38
  • 59
AstroCab
  • 11
  • 4

1 Answers1

0

In the code you have posted, Hist_2D computes the density map that is then displayed by cgImage. Since you already have the matrix you want to display (data), you can simply run: cgImage, data, /axes, /scale, /keep, xrange=[0.04,2.70], yrange=[-1.30,3.00]

ejb
  • 145
  • 8
  • Thanks, but it does not seem to solve my problem! The code should allow me to do everything like the above code (using Hist_2D) : logarithmic axes and contour. – AstroCab Apr 12 '18 at 07:52
  • The contours are trivial; just replace density by data and maxDensity by 1 in the cgContour line of Plot2. I'm not sure what you mean for the axes. For evenly spaced bins but logarithmic labels, check [this link](http://www.idlcoyote.com/graphics_tips/minorlog.html). – ejb Apr 12 '18 at 12:06