(30) Trigonometric functions plotted in graph mode

Next, we continue with a simple mathematical illustration of sine and cosine, highlighting the graph mode for linear projections and the new curved vectors for angles.

The script simply draws a graph basemap, computes sine and cosine and plots them as lines, then indicates on a circle that these quantities are simply the projections of an unit vector on the x- and y-axis, at the given angle.

using GMT
resetGMT() # hide

basemap(region=(0,360,-1.25,1.75), frame=(axes=:WS, title="Two Trigonometric Functions"), xaxis=(annot=90, ticks=30, suffix="@."), yaxis=(annot=1, grid=10), par=(MAP_FRAME_TYPE=:graph, MAP_VECTOR_SHAPE=0.5), figsize=(20,15), portrait=false)

# Draw sine an cosine curves
plot!(cosd.(linspace(0,360,360)), lw=3)
plot!(sind.(linspace(0,360,360)), pen="3p,0_6:0", par=(:PS_LINE_CAP,:round))

# Indicate the x-angle = 120 degrees
plot!([120 -1.25; 120 1.25], pen=(0.5, :dash))

T = mat2ds([360 1; 360 0; 120 -1.25; 370 -1.35; -5 1.85],
    ["18p,Times-Roman RB x = cos(@%12%a@%%)", "18p,Times-Roman RB y = sin(@%12%a@%%)", 
    "14p,Times-Roman LB 120@.", "24p,Symbol LT a", "24p,Times-Roman RT x,y"])

text!(T, offset=(away=true, shift=0.2), noclip=true, font="", justify="")

# Draw a circle and indicate the 0-70 degree angle
plot!([0 0], region=(-1,1,-1,1), proj=:linear, figscale=3.81, marker=:circle, ms=5.1, ml=1, noclip=true, xshift=9, yshift=7)
plot!(lw="",
    [NaN NaN
#     > x-gridline  -Wdefault
    -1 0
    1 0
    NaN NaN
#     > y-gridline  -Wdefault
    0 -1
    0 1
    NaN NaN
#     > angle = 0
    0 0
    1 0
    NaN NaN
#     > angle = 120
    0 0
    -0.5 0.866025])
plot!(lw=2,
    [NaN NaN
#     > x-gmt projection -W2p
    -0.3333 0
    0 0
    NaN NaN
#     > y-gmt projection -W2p
    -0.3333 0.57735
    -0.3333 0])

T = mat2ds([-0.16666 0 0; -0.3333 0.2888675 0; 0.22 0.27 -30; -0.33333 0.6 30],
    ["12p,Times-Roman CT x", "12p,Times-Roman RM y", "12p,Symbol CB a", "12p,Times-Roman LB 120@."])
text!(T, offset=(away=true, shift=0.1), font="", angle="", justify="")

plot!([0 0 1.25 0 120], marker=:matang, ms="0.4+e", ml=1, fill=:black, show=true)
Error: /undefined in nan
Operand stack:   0   0   0
Execution stack:   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1944   1   3   %oparray_pop   1943   1   3   %oparray_pop   1928   1   3   %oparray_pop   1801   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:   --dict:758/1123(ro)(G)--   --dict:0/20(G)--   --dict:85/200(L)--   --dict:171/250(L)--
Current allocation mode is local
Last OS error: No such file or directoryCurrent file position is 29970
psconvert [ERROR]: System call [@"C:\programs\gs\bin\gswin64c.exe" -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true "c:\TMP/GMTjl_j.ps" 2> "./psconvert_30740c.bb"] returned error 1.
Something went wrong when calling the module. GMT error number = 79

Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] gmt(::String)
    @ GMT C:\Users\j\.julia\dev\GMT\src\gmt_main.jl:166
  [3] showfig(d::Dict{Symbol, Any}, fname_ps::String, fname_ext::String, opt_T::String, K::Bool, fname::String)
    @ GMT C:\Users\j\.julia\dev\GMT\src\common_options.jl:4195
  [4] finish_PS_module_barr_last(d::Dict{Symbol, Any}, cmd::Vector{String}, fname::String, fname_ext::String, opt_extra::String, output::String, opt_T::String, K::Bool, P::Nothing)
    @ GMT C:\Users\j\.julia\dev\GMT\src\common_options.jl:4577
  [5] finish_PS_module(d::Dict{Symbol, Any}, cmd::Vector{String}, opt_extra::String, K::Bool, O::Bool, finish::Bool, args::GMTdataset{Float64, 2})
    @ GMT C:\Users\j\.julia\dev\GMT\src\common_options.jl:4515
  [6] prep_and_call_finish_PS_module
    @ C:\Users\j\.julia\dev\GMT\src\common_options.jl:4420 [inlined]
  [7] prep_and_call_finish_PS_module(d::Dict{Symbol, Any}, cmd::Vector{String}, opt_extra::String, K::Bool, O::Bool, finish::Bool, arg1::GMTdataset{Float64, 2}, arg2::Nothing, arg3::Nothing, arg4::Nothing)
    @ GMT C:\Users\j\.julia\dev\GMT\src\common_options.jl:4418
  [8] _common_plot_xyz(cmd0::String, arg1::GMTdataset{Float64, 2}, caller::String, O::Bool, K::Bool, is3D::Bool, d::Dict{Symbol, Any})
    @ GMT C:\Users\j\.julia\dev\GMT\src\psxy.jl:257
  [9] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
 [10] invokelatest
    @ .\essentials.jl:889 [inlined]
 [11] common_plot_xyz
    @ C:\Users\j\.julia\dev\GMT\src\psxy.jl:19 [inlined]
 [12] _plot
    @ C:\Users\j\.julia\dev\GMT\src\plot.jl:125 [inlined]
 [13] plot(arg1::Matrix{Float64}; first::Bool, kw::@Kwargs{marker::Symbol, ms::String, ml::Int64, fill::Symbol, show::Bool})
    @ GMT C:\Users\j\.julia\dev\GMT\src\plot.jl:103
 [14] plot
    @ C:\Users\j\.julia\dev\GMT\src\plot.jl:101 [inlined]
 [15] #plot!#738
    @ C:\Users\j\.julia\dev\GMT\src\plot.jl:127 [inlined]
 [16] top-level scope
    @ In[2]:52