Metview's documentation is now on readthedocs!

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Download source and data


Histogram Legend Example
# Metview Macro

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

# ------------------------------------------------------------------
# Tags: contour,legend
# Title: Positional and Histogram Legend
# Description: Demonstrates how to combine two fields into a single plot
#              using contour and shade. A histogram legend is used for one
#              of the fields.
# See also:
# https://software.ecmwf.int/magics/Legend+examples+legend3
# ------------------------------------------------------------------

# read the input grib files (temperature and geopotential)
my_data1 = read("./t850.grb")
my_data2 = read("./z500.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 temperature field
my_contour1 = mcont(contour_level_selection_type   : "LEVEL_LIST",
                    contour_level_list             : [-10.0,-8.0,-6.0,-4.0,-2.0,0.0,2.0,4.0,6.0,8.0,10.0],
                    contour                        : "OFF",
                    contour_label                  : "OFF",
                    contour_hilo                   : "OFF",
                    legend                         : "ON",
                    contour_shade                  : "ON",
                    contour_shade_method           : "AREA_FILL",  
                    contour_shade_colour_direction : "CLOCKWISE",
                    contour_shade_max_level_colour : "RED",
                    contour_shade_min_level_colour : "BLUE")

# set up a black contour line for the geopotential field
my_contour2 = mcont(contour_level_selection_type : "INTERVAL",
                    contour_line_colour          : "BLACK",
                    contour_line_thickness       : 1,
                    contour_hilo_height          : 0.25,
                    contour_interval             : 5.00,
                    contour_hilo                 : "ON",
                    contour_hilo_quality         : "HIGH",
                    contour_highlight_colour     : "BLACK",
                    contour_highlight_thickness  : 2,
                    contour_label                : "OFF",
                    legend                       : "OFF")

# set up the coastlines
my_coast= mcoast(map_coastline_resolution : "HIGH",
                 map_grid_colour          : "CHARCOAL",
                 map_grid                 : "ON",
                 map_coastline_colour     : "CHARCOAL")

# set up the title
my_title = mtext(text_font_size     : 0.60,
                 text_lines         : ["Positional and histogram legend","","","","","",""],
                 text_justification : "LEFT",
                 text_colour        : "CHARCOAL")

# set up an histogram legend for the temperature field
my_legend =  mlegend(legend_box_mode             : "POSITIONAL",
                     legend_box_x_position       : 1.00,
                     legend_box_x_length         : 27.00,
                     legend_box_y_position       : 16.00,
                     legend_box_y_length         : 3.00,
                     legend_display_type         : "HISTOGRAM",
                     legend_histogram_max_value : "ON",
                     legend_label_frequency      : 1,
                     legend_text_font_size       : 0.40,
                     legend_text_colour          : "BLACK",
                     legend_title                : "ON",
                     legend_title_text           : "Temperature at 850 hPa")


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

# plot the map
plot(my_view,my_data1,my_contour1,my_data2,my_contour2,my_coast,my_title,my_legend)
  • No labels