Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot overlay images #2599

Merged
merged 9 commits into from Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added doc/user_guide/images/plot_images_overlay.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions doc/user_guide/visualisation.rst
Expand Up @@ -736,6 +736,25 @@ __ plot.spectra_
functionality is only enabled if a ``matplotlib`` backend that supports the
``button_press_event`` in the figure canvas is being used.

It is also possible to plot multiple images overlayed on the same figure by
passing the argument `overlay=True` to the
:py:func:`~.drawing.utils.plot_images` function. This should only be done when
images have the same scale (eg. for elemental maps from the same dataset).
Using the same data as above, the Fe and Pt signals can be plotted using
different colours. Any color can be input via matplotlib color characters or
hex values.

.. code-block:: python

>>> si_EDS = hs.load("core_shell.hdf5")
>>> im = si_EDS.get_lines_intensity()
>>> hs.plot.plot_images(im,scalebar='all', overlay=True, suptitle=False,
>>> axes_decor='off')

.. figure:: images/plot_images_overlay.png
:align: center
:width: 500

.. _plot.spectra:

Plotting several spectra
Expand Down
401 changes: 266 additions & 135 deletions hyperspy/drawing/utils.py

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions hyperspy/tests/drawing/test_plot_signal2d.py
Expand Up @@ -561,3 +561,19 @@ def test_plot_autoscale_data_changed(autoscale):
else:
np.testing.assert_allclose(imf._vmin, _vmin)
np.testing.assert_allclose(imf._vmax, _vmax)

@pytest.mark.parametrize("axes_decor", ['all', 'off'])
@pytest.mark.parametrize("label", ['auto', ['b','g']])
@pytest.mark.parametrize("colors", ['auto', ['b','g']])
@pytest.mark.parametrize("alphas", [1.0, [0.9,0.9]])
@pytest.mark.mpl_image_compare(baseline_dir=baseline_dir,
tolerance=default_tol, style=style_pytest_mpl)
def test_plot_overlay(axes_decor,label,colors,alphas):
s1 = hs.signals.Signal2D(np.arange(100).reshape(10, 10))
s2 = hs.signals.Signal2D(np.arange(99,-1,-1).reshape(10, 10))
ax = hs.plot.plot_images([s1,s2], overlay=True, scalebar='all',
label=label, suptitle=False,
axes_decor=axes_decor, colors=colors,
alphas=alphas)

return ax[0].figure