def test__uses_figure_or_subplot_configs_correctly(self):

        figure = aplt.Figure(figsize=(8, 8))
        cmap = aplt.Cmap(cmap="warm")

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == (8, 8)
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "warm"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"

        figure = aplt.Figure()
        figure.is_for_subplot = True

        cmap = aplt.Cmap()
        cmap.is_for_subplot = True

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == None
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "jet"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"
Example #2
0
    def test__plot__works_for_reasonable_range_of_values(self):

        figure = aplt.Figure()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(fraction=1.0, pad=2.0)
        cb.set()
        figure.close()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(
            fraction=0.1,
            pad=0.5,
            manual_tick_values=[0.25, 0.5, 0.75],
            manual_tick_labels=[1.0, 2.0, 3.0],
        )
        cb.set()
        figure.close()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(fraction=0.1, pad=0.5)
        cb.set_with_color_values(cmap=aplt.Cmap().config_dict["cmap"],
                                 color_values=[1.0, 2.0, 3.0])
        figure.close()
    def test__open_and_close_subplot_figures(self):

        figure = aplt.Figure(figsize=(20, 20))

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        plotter.mat_plot_2d.figure.open()

        assert plt.fignum_exists(num=1) is True

        plotter.mat_plot_2d.figure.close()

        assert plt.fignum_exists(num=1) is False

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        assert plt.fignum_exists(num=1) is False

        plotter.open_subplot_figure(number_subplots=4)

        assert plt.fignum_exists(num=1) is True

        plotter.mat_plot_2d.figure.close()

        assert plt.fignum_exists(num=1) is False
Example #4
0
    def test__aspect_from_shape_native(self):

        figure = aplt.Figure(aspect="auto")

        aspect = figure.aspect_from_shape_native(shape_native=(2, 2))

        assert aspect == "auto"

        figure = aplt.Figure(aspect="square")

        aspect = figure.aspect_from_shape_native(shape_native=(2, 2))

        assert aspect == 1.0

        aspect = figure.aspect_from_shape_native(shape_native=(4, 2))

        assert aspect == 0.5
Example #5
0
    def test__open_and_close__open_and_close_figures_correct(self):

        figure = aplt.Figure()

        figure.open()

        assert plt.fignum_exists(num=1) is True

        figure.close()

        assert plt.fignum_exists(num=1) is False
Example #6
0
    def test__overlay_array__works_for_reasonable_values(self):

        arr = aa.Array2D.manual_native(array=[[1.0, 2.0], [3.0, 4.0]],
                                       pixel_scales=0.5,
                                       origin=(2.0, 2.0))

        figure = aplt.Figure(aspect="auto")

        array_overlay = aplt.ArrayOverlay(alpha=0.5)

        array_overlay.overlay_array(array=arr, figure=figure)
Example #7
0
    def test__loads_values_from_config_if_not_manually_input(self):

        figure = aplt.Figure()

        assert figure.config_dict["figsize"] == (7, 7)
        assert figure.config_dict["aspect"] == "square"

        figure = aplt.Figure(aspect="auto")

        assert figure.config_dict["figsize"] == (7, 7)
        assert figure.config_dict["aspect"] == "auto"

        figure = aplt.Figure()
        figure.is_for_subplot = True

        assert figure.config_dict["figsize"] == None
        assert figure.config_dict["aspect"] == "square"

        figure = aplt.Figure(figsize=(6, 6))
        figure.is_for_subplot = True

        assert figure.config_dict["figsize"] == (6, 6)
        assert figure.config_dict["aspect"] == "square"
Example #8
0
    def test__subplot_figsize_for_number_of_subplots(self):

        plotter = aplt.SubPlotter()

        figsize = plotter.get_subplot_figsize(number_subplots=1)

        assert figsize == (18, 8)

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (13, 10)

        plotter = aplt.SubPlotter(figure=aplt.Figure(figsize=(20, 20)))

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (20, 20)
Example #9
0
    def test__set_legend_works_for_plot(self):

        figure = aplt.Figure(aspect="auto")

        figure.open()

        line = aplt.YXPlot(linewidth=2, linestyle="-", c="k")

        line.plot_y_vs_x(y=[1.0, 2.0, 3.0],
                         x=[1.0, 2.0, 3.0],
                         plot_axis_type="linear",
                         label="hi")

        legend = aplt.Legend(fontsize=1)

        legend.set()

        figure.close()
    def test__subplot_figsize_for_number_of_subplots(self):

        plotter = abstract_plotters.AbstractPlotter()

        figsize = plotter.get_subplot_figsize(number_subplots=1)

        assert figsize == (18, 8)

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (13, 10)

        figure = aplt.Figure(figsize=(20, 20))

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=aplt.MatPlot2D(
            figure=figure))

        figsize = plotter.get_subplot_figsize(number_subplots=4)

        assert figsize == (20, 20)
Example #11
0
    def test__figure__from_config_or_via_manual_input(self):

        plotter = aplt.Plotter()

        assert plotter.figure.figsize == (7, 7)
        assert plotter.figure.aspect == "auto"

        plotter = aplt.Plotter(figure=aplt.Figure(aspect="auto"))

        assert plotter.figure.figsize == (7, 7)
        assert plotter.figure.aspect == "auto"

        sub_plotter = aplt.SubPlotter()

        assert sub_plotter.figure.figsize == None
        assert sub_plotter.figure.aspect == "square"

        sub_plotter = aplt.SubPlotter(figure=aplt.Figure.sub(figsize=(6, 6)))

        assert sub_plotter.figure.figsize == (6, 6)
        assert sub_plotter.figure.aspect == "square"
Example #12
0
    image_path=dataset_path + "image.fits",
    noise_map_path=dataset_path + "noise_map.fits",
    psf_path=dataset_path + "psf.fits",
    pixel_scales=0.1,
)

# We can plot an image as follows:

aplt.imaging.image(imaging=imaging)

# Does the figure display correctly on your computer screen?
#
# If not, you can customize a number of matplotlib setup options using a Plotter object in PyAutoArray.

plotter = aplt.Plotter(
    figure=aplt.Figure(figsize=(7, 7)),
    ticks=aplt.Ticks(ysize=8, xsize=8),
    labels=aplt.Labels(ysize=6, xsize=6, titlesize=12),
)

aplt.imaging.image(imaging=imaging, plotter=plotter)

# Many matplotlib setup options can be customized, but for now we're only concerned with making sure figures display
# cleanly in your Jupter Notebooks. However, for future reference, a description of all options can be found in the file
# 'autolens_workspace/plot/mat_objs.py'.

# Ideally, we wouldn't need to specify a new plotter every time we plot an image, especially as you'll be changing
# the same option to the same value over and over again (e.g. the figsize). Fortunately, the default values used by
# PyAutoLens can be fully customized.

# Checkout the the file 'autolens_workspace/config/visualize/figures.ini'.