def test_copy(): """Test that the copy method works for all classes in `declarative.py`.""" # Copies of plot objects objects = [ImagePlot(), ContourPlot(), FilledContourPlot(), BarbPlot(), PlotObs(), PlotGeometry()] for obj in objects: obj.time = datetime.now() copied_obj = obj.copy() assert obj is not copied_obj assert obj.time == copied_obj.time # Copies of MapPanel and PanelContainer obj = MapPanel() obj.title = 'Sample Text' copied_obj = obj.copy() assert obj is not copied_obj assert obj.title == copied_obj.title obj = PanelContainer() obj.size = (10, 10) copied_obj = obj.copy() assert obj is not copied_obj assert obj.size == copied_obj.size # Copies of plots in MapPanels should not point to same location in memory obj = MapPanel() obj.plots = [PlotObs(), PlotGeometry(), BarbPlot(), FilledContourPlot(), ContourPlot(), ImagePlot()] copied_obj = obj.copy() for i in range(len(obj.plots)): assert obj.plots[i] is not copied_obj.plots[i]
def test_declarative_colorbar_fontsize(): """Test adjusting the font size of a colorbar.""" data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False)) cfill = FilledContourPlot() cfill.data = data cfill.field = 'Temperature_isobaric' cfill.level = 300 * units.hPa cfill.time = datetime(2010, 10, 26, 12) cfill.contours = list(range(210, 250, 2)) cfill.colormap = 'BuPu' cfill.colorbar = 'horizontal' cfill.colorbar_fontsize = 'x-small' panel = MapPanel() panel.area = (-124, -72, 20, 53) panel.projection = 'lcc' panel.layers = ['coastline', 'borders', 'usstates'] panel.plots = [cfill] pc = PanelContainer() pc.size = (8, 8) pc.panels = [panel] pc.draw() return pc.figure
def test_colorfill_no_colorbar(cfeature): """Test that we can use ContourFillPlot.""" data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) contour = FilledContourPlot() contour.data = data contour.level = 700 * units.hPa contour.field = 'Temperature' contour.colormap = 'coolwarm' contour.colorbar = None panel = MapPanel() panel.area = (-110, -60, 25, 55) panel.layers = [cfeature.STATES] panel.plots = [contour] pc = PanelContainer() pc.panel = panel pc.size = (8, 8) pc.draw() return pc.figure