[Thread Prev][Thread Next][Index]

Re: [ferret_users] How to make a plot with 2 Y axis



On 8 Nov 2021 Olivier Marti contributed a useful ferret script, COPY_VIEWPORT.JNL, to answer partially Pierre Friedlingstein’s ferret user question about how to make a plot with a second y axis.  It happens that I was writing my own script to modernize the old LEFT_AXIS_PLOT.JNL and RIGHT_AXIS_PLOT.JNL scripts.  Olivier’s script came at just the right time.  

I attach my script PLOT_2_Y_AXES_COMMON_X_AXIS.JNL script.  It plots 2 different y variables, one on the left y axis and one on the right y axis, on a common x axis.  The benefit over the old scripts is that you can put the ferret plot commands, with many options, in the input left and right axis symbol command lines.  The script is below, and also an example script, separated by a line of  *******.



\cancel mode verify

! PLOT_2_Y_AXES_COMMON_X_AXIS.JNL plots 2 y values, on left and right axes, on a common x axis. 

! Programmed by E.D. Cokelet, NOAA/PMEL, Edward.D.Cokelet@xxxxxxxx, 5 Nov 2021
! Last modified 15 Nov 2021.   

! Usage:
! Define the single x (x_bottom_var) and the two y values (y_left_var and y_right_var) you wish to plot.  Set a viewport, and set up the plot instructions.

! set viewport full
! define symbol left_instructions   = plot/vs/title="Test Plot"/line/color=red/thick/hlim=-1:12/vlim=-2:150
! define symbol right_instructions = plot/vs/sym=27/color=green/thick/nolabel/vlim=-20:600
! go plo class="">set variable/title="Right Var"/units="m" right_var ! right y axis label becomes "Right Var (m)"

define symbol left_instructions = plot/vs/title="Test Plot"/line/color=red/thick/hlim=-1:12/vlim=-2:150
define symbol right_instructions = plot/vs/sym=27/color=green/thick/hlim=-50:100/vlim=-20:600


go plot_2_y_axes_common_x_axis ($left_instructions) xx left_var ($right_instructions) right_var

!pause


! Make another test plot with less options set up

set window 2
set view full

let xx2 = 10*xx
let left_var2 = 10*left_var
let right_var2 = (5*xx^2 + 10) * 10^(-10)

define symbol left_instructions2 = plot/vs/line/color=black
define symbol right_instructions2 = plot/vs/sym=27/color=lightblue

go plot_2_y_axes_common_x_axis ($left_instructions2) xx2 left_var2 ($right_instructions2) right_var2




______________________________________________

Edward (Ned) D. Cokelet, Ph.D. Oceanographer
NOAA/PMEL off:  206-526-6820
7600 Sand Point Way NE fax: 206-526-6485
Seattle, WA 98115-6349

Edward.D.Cokelet@xxxxxxxx

The contents of this message are mine personally and do not necessarily reflect any position of the Government or the National Oceanic and Atmospheric Administration.





[Thread Prev][Thread Next][Index]