X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



118 Rate this article:
No rating

How to plot two graphics with different data extents in the same view using IDL Object Graphics

With IDL Object Graphics, plotting two graphics with different data extents in the same graphic window requires normalizing the range of the second graphic to fit the extension of the first one. If not, the two graphics will not fit within the same view.

Here is an example of such normalization based on two random datasets, with two different extents along the Y-axis.

 

Code example:

 

PRO test_IDLgrPlot


;create 2 random datasets

d1 = SMOOTH(RANDOMU(Seed1, 100)*(-200),10)

d2 = SMOOTH(RANDOMU(Seed, 100)*0.1,5)


;create window hierarchy

mywindow = IDLgrWindow()

myview = IDLgrView()

mymodel = IDLgrModel()


; create plot objects

plot1= IDLgrPlot(INDGEN(100),d1,COLOR=[0,0,255])

plot2= IDLgrPlot(INDGEN(100),d2,COLOR=[0,255,0])


; add plot objects and model to the view

myview.Add, mymodel

mymodel.Add, plot1

mymodel.Add, plot2


; normalized plot1 extension (blue line) to fit the view

plot1.GetProperty, XRANGE = xr, YRANGE = yr

xs = NORM_COORD(xr)

xs[0] = xs[0] - 0.5

ys = NORM_COORD(yr)

ys[0] = ys[0] - 0.5

plot1.SetProperty, XCOORD_CONV = xs, YCOORD_CONV = ys


; normalized plot2 extension (green line) to fit the view and to fit the same extension as plot1

plot2.GetProperty, XRANGE = xr2, YRANGE = yr2

xs2 = NORM_COORD(xr2)

xs2[0] = xs2[0] - 0.5

ys2 = NORM_COORD(yr2)

ys2[0] = ys2[0] - 0.5

plot2.SetProperty, XCOORD_CONV = xs2, YCOORD_CONV = ys2


; create axis

oTextXAxis = IDLgrText('X axis')

oTextYAxis = IDLgrText('Blue line')

oTextYAxis2 = IDLgrText('Green line')


oPlotYAxis = IDLgrAxis( 1, /EXACT, RANGE = yr, $

    XCOORD_CONV = xs, YCOORD_CONV = ys,TITLE = oTextYAxis, $

    LOCATION = [xr[0], yr[0]], TICKDIR = 0, $

    TICKLEN = (0.02*(xr[1] - xr[0])))


oPlotXAxis = IDLgrAxis( 0, /EXACT, RANGE = xr, $

    XCOORD_CONV = xs, YCOORD_CONV = ys,TITLE = oTextXAxis, $

    LOCATION = [xr[0], yr[0]], TICKDIR = 0, $

    TICKLEN = (0.02*(yr[1] - yr[0])))


oPlotYAxis2 = IDLgrAxis( 1, /EXACT, RANGE = yr2, $

    XCOORD_CONV = xs, YCOORD_CONV = ys2, TITLE = oTextYAxis2,$

    LOCATION = [xr[1], yr[0]], TICKDIR = 0, TEXTPOS=1, $

    TICKLEN = (0.02*(xr[1] - xr[0])))


oPlotXAxis2 = IDLgrAxis( 0, /EXACT, RANGE = xr, $

    XCOORD_CONV = xs, YCOORD_CONV = ys, $

    LOCATION = [xr[0], yr[1]],/NOTEXT,MAJOR=0,MINOR=0)   


;add axis to the model 

mymodel.Add, oPlotXAxis

mymodel.Add, oPlotYAxis

mymodel.Add, oPlotYAxis2

mymodel.Add, oPlotXAxis2


;draw the view

mywindow.Draw, myview


END

 

The graphic generated will be similar to the following:

 

-----------------------------------------------

created by BC on 2/19/2025

Reviewd by BC (US) on 2/28/2025

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »