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.



6026 Rate this article:
No rating

How to produce a plot with a linear Y axis and a logarithmic Y axis


Topic
The question is how to produce a plot that has both a linear and a logarithmic Y axes.
The following code is an example of how to accomplish this in IDL using the new graphics functions.

Discussion
To be able to have two different data sets in a right and left Y axis, the user will need to setup a separate data space to draw a second overlapping plot and axis (see, TARGET=p_log below). Otherwise if a user attempts to plot in the same data space as the original plot, the log=1 keyword in AXIS() will change the original plot's data space to be logarithmic.

For more examples on plots with two data sets see the following link:
http://www.harrisgeospatial.com/docs/plot_2d.html

Here is the code to create the above plot in IDL:

;make some data
f=findgen(200)

;plot the data
p = PLOT(f, 'b', $
    AXIS_STYLE = 1, $ ; make only x & y axes, not box axes
    MARGIN = [0.15, 0.15, 0.20, 0.15]); leave room for bottom & right axes

;create the log plot
p_log = PLOT(f, 'r', $
    /CURRENT, $
    YRANGE = [1,max(f)], $
    AXIS_STYLE = 0, $                  ; no axes
    MARGIN = [0.15, 0.15, 0.20, 0.15]) ; need to use the same margin as above

;make the log axis for the y direction
logy = AXIS('y', $
    TARGET = p_log, $
    LOCATION = [max(p_log.xrange),0,0], $ ; right y-axis, data coordinates
    TEXTPOS = 1, $ ;text on the outside
    log = 1,$ ; specify the log scale
    tickdir = 1);have the ticks on the inside of the plot
    
;manipulate the locations/labels of the resulting axis
;using the first axis so that the axes have the same labels

first_yaxis=(p.axes)[1] 
logy.major= n_elements(first_yaxis.tickvalues)
names=logy.tickvalues
names[1:*]=(first_yaxis.tickvalues)[1:*]
logy.tickvalues=names
logy.minor = 3

 

Reviewed by ZN (1-July-2015), JU (1-July-2015)

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 »