Skip to content

Commit

Permalink
Merge pull request Unidata#989 from dopplershift/declarative
Browse files Browse the repository at this point in the history
Declarative/simplified plotting
  • Loading branch information
jrleeman authored Jan 6, 2019
2 parents 2070cb2 + e16c0b5 commit cee9d4d
Show file tree
Hide file tree
Showing 12 changed files with 1,189 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/installguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ currently supporting Python 2.7.
* scipy >= 0.17.0
* pint >= 0.8
* xarray >= 0.10.7
* traitlets >= 4.3.0
* enum34 (for python < 3.4)
* pooch >= 0.1, < 0.3

Expand Down
50 changes: 50 additions & 0 deletions examples/plots/Combined_plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
Combined Plotting
=================
Demonstrate the use of MetPy's simplified plotting interface combining multiple plots.
Also shows how to control the maps that are plotted. Plots sample NARR data.
"""

import xarray as xr

from metpy.cbook import get_test_data
from metpy.plots import ContourPlot, ImagePlot, MapPanel, PanelContainer
from metpy.units import units

# Use sample NARR data for plotting
narr = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

###########################
# Create a contour plot of temperature
contour = ContourPlot()
contour.data = narr
contour.field = 'Temperature'
contour.level = 850 * units.hPa
contour.linecolor = 'red'
contour.contours = 15

###########################
# Create an image plot of Geopotential height
img = ImagePlot()
img.data = narr
img.field = 'Geopotential_height'
img.level = 850 * units.hPa


###########################
# Plot the data on a map
panel = MapPanel()
panel.area = 'us'
panel.layers = ['coastline', 'borders', 'states', 'rivers', 'ocean', 'land']
panel.title = 'NARR Example'
panel.plots = [contour, img]

pc = PanelContainer()
pc.size = (10, 8)
pc.panels = [panel]
pc.show()
31 changes: 31 additions & 0 deletions examples/plots/Simplified_Image_Plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
Simple Plotting
===============
Demonstrate the use of MetPy's simplified plotting interface.
Plots a sample satellite image file.
"""

import xarray as xr

from metpy.cbook import get_test_data
from metpy.io import GiniFile
from metpy.plots import ImagePlot, MapPanel, PanelContainer

data = xr.open_dataset(GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini')))

img = ImagePlot()
img.data = data
img.field = 'IR'
img.colormap = 'Greys_r'

panel = MapPanel()
panel.plots = [img]

pc = PanelContainer()
pc.panels = [panel]
pc.show()
2 changes: 2 additions & 0 deletions metpy/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
from . import _mpl # noqa: F401
from ._util import add_metpy_logo, add_timestamp, add_unidata_logo, convert_gempak_color
from .ctables import * # noqa: F403
from .declarative import * # noqa: F403
from .skewt import * # noqa: F403
from .station_plot import * # noqa: F403
from .wx_symbols import * # noqa: F403

logger = logging.getLogger(__name__)

__all__ = ctables.__all__[:] # pylint: disable=undefined-variable
__all__.extend(declarative.__all__) # pylint: disable=undefined-variable
__all__.extend(skewt.__all__) # pylint: disable=undefined-variable
__all__.extend(station_plot.__all__) # pylint: disable=undefined-variable
__all__.extend(wx_symbols.__all__) # pylint: disable=undefined-variable
Expand Down
Loading

0 comments on commit cee9d4d

Please sign in to comment.