Metview's documentation is now on readthedocs!

Download source and data


Time Series Curves From Lists Example
# Metview Macro

# **************************** LICENSE START ***********************************
#
# Copyright 2018 ECMWF. This software is distributed under the terms
# of the Apache License version 2.0. In applying this license, ECMWF does not
# waive the privileges and immunities granted to it by virtue of its status as
# an Intergovernmental Organization or submit itself to any jurisdiction.
#
# ***************************** LICENSE END ************************************

# ------------------------------------------------------
# Description: Generates some dummy data in lists
#              and plots as a time series
# ------------------------------------------------------


# Define our range of dates

date_start = 2012-07-27
num_days   = 16


# Build our set of dates and values for the curves

dates      = nil
values_sin = nil
values_cos = nil

for i = 0 to num_days by hour(6) do
    dates  = dates & ([date_start + i])
    values_sin = values_sin & [sin(i)]
    values_cos = values_cos & [cos(i)]
end for


# graph plotting attributes

graph_attrib_sin    = mgraph
(
    legend            : 'on',
    graph_line_colour : "blue",
    graph_line_style  : "dash"
)

graph_attrib_cos    = mgraph
(
    legend            : "on",
    graph_line_colour : "red"
)


# define the curves and associate them with the
# plotting attributes

curve_def_sin = input_visualiser
(
    input_x_type          : "date",
    input_date_x_values   : dates,
    input_y_values        : values_sin
)

curve_def_cos = input_visualiser
(
    input_x_type          : "date",
    input_date_x_values   : dates,
    input_y_values        : values_cos
)


legend_curves = mlegend
(
    legend_display_type      : "disjoint",
    legend_text_composition  : "user_text_only",
    legend_text_font_size    : 0.4,
    legend_user_lines        : ['sin curve', 'cos curve']
)



# define the plot's title

text_plot = mtext
(
    text_line_1 : "Example curve plot"
)



# define the output plot file
setoutput(pdf_output(output_name : 'time_series_curve_from_lists'))


# Call function to build layout (defined at end of macro)
dw = build_layout (dates)


# Plot the curves

plot (dw, curve_def_sin, graph_attrib_sin, curve_def_cos, graph_attrib_cos,
      text_plot, legend_curves)


#################################################################
#
#                End of Main Macro
#
#################################################################


# Function to build the layout

function build_layout(dates : list)

    horizontal_axis = maxis
    (
        axis_date_type : 'days'
    )

    vertical_axis = maxis
    (
        axis_title_text  : 'y-axis title',
        axis_orientation : 'vertical'
    )

    cview = cartesianview
    (  
        x_axis_type     : "date",
        x_date_min      : dates [1],
        x_date_max      : dates [count(dates)],
        y_axis_type     : "regular",
        y_automatic     : 'on',
        horizontal_axis : horizontal_axis,
        vertical_axis   : vertical_axis
    )

    page1 = plot_page
    (
        view  : cview
    )

    display_window = plot_superpage
    (
        pages : [page1]
    )

    return display_window

end build_layout