Metview's documentation is now on readthedocs!

Download source and data


Curve With Log Y Axis Example
"""
Cartesian view curve with logarithmic y axis
============================================
"""

#  **************************** LICENSE START ***********************************
#
#  Copyright 2020 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 ************************************
#

import metview as mv


# read the GRIB data into a fieldset
g = mv.read('ozone_pl.grib')

# extract the values at a point, and the vertical levels
levels = mv.grib_get_double(g, 'level')
ozone = mv.nearest_gridpoint(g, [-85, 0])


# define curve
vis_curve = mv.input_visualiser(input_x_values=ozone, input_y_values=levels)

# define curve style
gr_curve = mv.mgraph(
    graph_type="curve", graph_line_colour="coral", graph_line_thickness=4
)

# define a nice title for the x axis
# use object methods to get metadata, just to show the alternative
# to using functions
x_title = g[0].grib_get_string("name") + " in " + g[0].grib_get_string("units")
x_axis = mv.maxis(axis_title_text=x_title)

# define y axis title
y_title = "Pressure in hPa"
y_axis = mv.maxis(axis_title_text=y_title)


# define view, setting a log y axis
view = mv.cartesianview(x_automatic="off",
                        x_min=0,
                        x_max=max(ozone),
                        y_automatic="on",
                        y_axis_type="logarithmic",
                        horizontal_axis=x_axis,
                        vertical_axis=y_axis)

# define the output plot file
mv.setoutput(mv.pdf_output(output_name="cartesian_log_y_axis"))

# generate plot
mv.plot(view, vis_curve, gr_curve)
Curve With Log Y Axis Example
# Metview Macro

#  **************************** LICENSE START ***********************************
#
#  Copyright 2020 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 ************************************
#

# read the GRIB data into a fieldset
g = read('ozone_pl.grib')

# extract the values at a point, and the vertical levels
levels = grib_get_double(g, 'level')
ozone = nearest_gridpoint(g, [-85, 0])


# define curve
vis_curve = input_visualiser(input_x_values: ozone, input_y_values: levels)

# define curve style
gr_curve = mgraph(
    graph_type: "curve", graph_line_colour: "coral", graph_line_thickness: 4
)

# define a nice title for the x axis
x_title = grib_get_string(g[1], "name") & " in " & grib_get_string(g[1], "units")
x_axis = maxis(axis_title_text: x_title)

# define y axis title
y_title = "Pressure in hPa"
y_axis = maxis(axis_title_text: y_title)


# define view, setting a log y axis
view = cartesianview(x_automatic: "off",
                      x_min: 0,
                      x_max: maxvalue(vector(ozone)),
                      y_automatic: "on",
                      y_axis_type: "logarithmic",
                      horizontal_axis: x_axis,
                      vertical_axis: y_axis)

# define the output plot file
setoutput(pdf_output(output_name: "cartesian_log_y_axis"))

# generate plot
plot(view, vis_curve, gr_curve)