Metview's documentation is now on readthedocs!

Download source and data


Disjoint Legend 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: Demonstrates how to show a disjoint legend with labels
#              for each level value.
# ------------------------------------------------------------------



# read the input grib file (temperature)
my_data = read("./t850.grb")

# set up the geographical view
my_view = geoview(map_area_definition : "CORNERS",
                  map_projection      : "POLAR_STEREOGRAPHIC",
                  area                : [21.51,-37.27,51.28,65.00])

# set up a shade contour with legend for the field
my_contour = mcont(contour_level_selection_type : "LEVEL_LIST",
                   contour_level_list           : [-48.0,-10.0,0.0,10.0,20.0,48.0],
                   contour_hilo                 : "OFF",
                   contour_label                : "OFF",
                   contour                      : "OFF",
                   legend                       : "ON",
                   contour_shade                : "ON",
                   contour_shade_colour_method  : "LIST",
                   contour_shade_method         : "AREA_FILL",
                   contour_shade_max_level      : 48.00,
                   contour_shade_min_level      : -48.00,
                   contour_shade_colour_list    : ["blue_purple"," greenish_blue"," blue_green"," yellow_green"," yellow"," orange"])

# set up an disjoint legend for the field
my_legend =  mlegend(legend_display_type     : "DISJOINT",
                     legend_text_composition : "USER_TEXT_ONLY",
                     legend_title            : "ON",
                     legend_user_lines       : ["extremely cold"," very cold"," cold"," temperate"," hot"],
                     legend_text_font_size   : 0.4,
                     legend_text_colour      : "BLACK",
                     legend_entry_text_width : 80.00,
                     legend_title_text       : "Temperature at 850 hPa")

# set up the coastlines
my_coast= mcoast(map_coastline_resolution : "MEDIUM")

# set up the title
my_title = mtext(text_font_size     : 0.6,
                 text_lines         : ["Disjoint legend with user defined labels"," "],
                 text_justification : "LEFT",
                 text_colour        : "CHARCOAL")

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

# plot the cartesian graph
plot(my_view,my_data,my_contour,my_coast,my_title,my_legend)
Disjoint Legend Example
# Metview Example

#  **************************** 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: Demonstrates how to show a disjoint legend with labels
#              for each level value.
# ------------------------------------------------------------------

import metview as mv

# read the input grib file (temperature)
my_data = mv.read("./t850.grb")

# set up the geographical view
my_view = mv.geoview(map_area_definition = "CORNERS",
                  map_projection         = "POLAR_STEREOGRAPHIC",
                  area                   = [21.51,-37.27,51.28,65.00])

# set up a shade contour with legend for the field
my_contour = mv.mcont(contour_level_selection_type = "LEVEL_LIST",
                   contour_level_list           = [-48.0,-10.0,0.0,10.0,20.0,48.0],
                   contour_hilo                 = "OFF",
                   contour_label                = "OFF",
                   contour                      = "OFF",
                   legend                       = "ON",
                   contour_shade                = "ON",
                   contour_shade_colour_method  = "LIST",
                   contour_shade_method         = "AREA_FILL",
                   contour_shade_max_level      = 48.00,
                   contour_shade_min_level      = -48.00,
                   contour_shade_colour_list    = ["blue_purple"," greenish_blue"," blue_green"," yellow_green"," yellow"," orange"])

# set up an disjoint legend for the field
my_legend =  mv.mlegend(legend_display_type     = "DISJOINT",
                     legend_text_composition = "USER_TEXT_ONLY",
                     legend_title            = "ON",
                     legend_user_lines       = ["extremely cold"," very cold"," cold"," temperate"," hot"],
                     legend_text_font_size   = 0.4,
                     legend_text_colour      = "BLACK",
                     legend_entry_text_width = 80.00,
                     legend_title_text       = "Temperature at 850 hPa")

# set up the coastlines
my_coast = mv.mcoast(map_coastline_resolution = "HIGH")

# set up the title
my_title = mv.mtext(text_font_size  = 0.6,
                 text_lines         = ["Disjoint legend with user defined labels"," "],
                 text_justification = "LEFT",
                 text_colour        = "CHARCOAL")

# define the output plot file
mv.setoutput(mv.pdf_output(output_name = 'legend2'))

# plot the cartesian graph
mv.plot(my_view, my_data, my_contour, my_coast ,my_title, my_legend)