如何使用 IDL 对象图形在同一视图中绘制具有不同数据范围的两个图形
使用IDL对象图形时,若要在同一图形窗口中绘制具有不同数据范围的图形,需要对第二个图形的范围进行归一化处理以匹配第一个图形的范围。否则,两个图形将无法适配到同一视图中。
以下是一个基于两个随机数据集的归一化示例,这两个数据集在Y轴上具有不同的范围。
代码示例:
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
生成的图形将类似于下图所示:


浙公网安备 33010602011771号