Skip to content

Commit

Permalink
Major update of spectra, plotting, CL tools (#89)
Browse files Browse the repository at this point in the history
Closes #84, closes #86, closes #87, closes #105

Summary of changes:

- New command line tool ``euphonic-intensity-map`` for plotting weighted
  2D Spectra e.g. Coherent neutron S(Q,w)
- Existing command line tools ``euphonic-dispersion`` and ``euphonic-dos``
  have been updated to also read force constants and Phonopy files.
  Arguments are also more consistent across tools so some may have changed,
  check the command line tool help for details.
- New ``Spectrum1DCollection`` object for containing 1D spectra with a
  shared x-axis (e.g. phonon dispersion modes)
- New ``plot_1d_to_axis`` and ``plot_2d_to_axis`` functions to allow
  plotting on specific axes
- ``get_bin_centres`` and ``get_bin_edges`` utility functions on spectra
- The ``ratio`` argument to ``plot_2d`` has been removed, it should no longer
  be required due to better management of relative axis sizes.
- The ``btol`` argument to ``plot_1d`` has been removed, it is recommended
  to use ``Spectrum1D.split()`` or ``Spectrum1DCollection.split()`` instead.
- The ``plot_dispersion`` function has been removed. It is now recommended
  to plot dispersion using ``plot_1d(QpointPhononModes.get_dispersion())``.
  See docs for details.

Commits:

* README Tweaks

This is a somewhat superficial change to allow the creation of a
feature branch PR for a more extensive set of work over multiple PRs

* Spectrum2D: rework plot_2d to use NonUniformImage; new script

Beginning work proposed in Issue #84

- Refactor plot_2d to use NonUniformImage. This cleans up a lot of the
  plotting logic, taking care of the irregular spacing for us.
- Break actual axis plotting into separate function that can be
  re-used for custom/complex layouts, while plot_2d remains a "fire
  and forget" tool returning a Figure
- Allow Normalize object to be passed, in preparation for
  implementation of multi-part plot with common colour scale
- Dump script used for testing/prototyping into scripts directory;
  with a bit more work this should become a good tool for users.

* Expand type-hinting of 2D spectrum plotting functions

* Proof-of-concept: seekpath band structure returning multiple spectra

Calling Seekpath is easy enough, but a bit of data manipulation is
required to split the output into separate branches.

Currently the spectrum for each segment is displayed separately. Having
demonstrated that this works we can move to combining them in plot_2d.

* Clean up neutron band structure script

* plot_2d: accept a sequence of Spectrum2D as input

Spectrum2D now uses subplots to present multiple spectra, as
appropriate for Brillouin-zone band structure plots.

The neutron band structure script has also had some minor upgrades.

* Add broadening to neutron band structure script

* neutron band structure script: fix y-units formatting

* 2D plotting: further cleanup using nifty Euphonic and numpy features

Some neat tricks were stolen from the 1D code

* Neutron band structure script: Support more file formats

* Neutron band structure: allow user to specify units

* neutron_band_structure.py: report number of modes being calculated

* 1D plot refactoring: separate phonons->Spectrum1D from plotting

plot_dispersion is doing a useful job of generating Spectrum1D
objects, but this is not accessible to the user. Split these functions.

* Further 1D plot refactoring

- Move main 1D plotting code into an internal "core" function
- Type hinting
- Lines option to neutron-band-structure; should be useful for testing
  work on band structure data
- Some tweaking to avoid import loops

* Spectrum classes: Spectrum1DCollection, Spectrum base class

This setup for a spectrum base class is a bit of a hack: rename
Spectrum1D to Spectrum, and inherit it to Spectrum1D. The purpose is
to make sure that isinstance(spectrum, Spectrum1D) will FAIL if the
spectrum is a Spectrum2D.

Ideally we would have some shared code in a Spectrum ABC, and unique
features in each subclass. But because there is a lot of "magic"
around setting the properties of these classes with appropriate units,
it is not so straightforward to establish abstract properties.

* Expand tests of Spectrum1DCollection, fix issues as encountered

* WIP: Spectrum1DCollection plotting

* Spectrum as abstract base: separate Spectrum1D, Spectrum2D features

This makes it far clearer which spectrum features are specifically
implemented for Spectrum1D and Spectrum2D, without adding much
redundancy.

* 1D plot: typing/logic tweaks

* Spectrum objects: implement split() method, test in Spectrum1D

Initially considered an axis='x' option to support splitting in other
directions. But as we're not implementing that now, there's no need to
include the optional argument yet.

* Spectrum1D split(): Expand test coverage

This now gives full coverage for the base Spectrum class and Spectrum1D
class.

The new tests are a bit verbose compared to the existing setup,
because the sample data is generated on the fly rather than read from
JSON. At this point while features and tests are being developed this
is a better workflow; it can be tidied up into JSON regression tests
once we are satisfied with the functionality.

* Basic tests: Spectrum1DCollection.split(), Spectrum2D.split()

* Refactor 1D plots: use _plot_1d_core, handle breakpoints there

- _split_line_idx are still being passed around, but the information
  is no longer used; instead, line breaks are inferred (just before
  plotting) by checking for identical neighbouring x-values

* get_dispersion to method, & further simplification of plot_1d

- The euphonic.util.get_dispersion() function is now a method on
  QpointPhononModes, returning a Spectrum1DCollection.
- plot_dispersion() is now almost empty; it passes btol to split()
  and calls plot_1d.
- btol option to plot_1d is removed; splitting should be performed
  before plotting
- _get_gridspec_kw no longer deals with breakpoints

* Major cleanup of neutron-band-structure using split() feature

* Spectrum1D: clean up split() tests using existing JSON framework

This process caught a bug: splitting can lead to numpy int64 values in
the x_tick_labels, which do not play well with JSON serialisation.

* Spectrum2D: clean up split() test using existing JSON framework

* JSON Test data for spectrum.split() tests

* Rework Spectrum1DCollection tests to use JSON references

In the process, a couple of useful errors/sanity-checks were
identified and included in Spectrum1DCollection

* pint import tweak for oldlibs

* neutron-band-structure review tweaks: emin/max, use to_spglib_cell()

- Provide user arguments to set energy range
- Default max to 5% above data
- Default min to zero if data does not go below zero
- Remove redundant implementation of to_spglib_cell()

* Whitespace cleanup

* Spectrum1DCollection test cleanup

* QpointPhononModes: re-order methods to match docs

* Refactor CLI tools so euphonic-dispersion can read FC

- Move most of the file-reading and band structure construction logic
  to euphonic.cli.utils

- Strip back neutron-band-structure to only produce spectrum plots

* Tweak breakpoint positions for band structure plots

* Fix some mistakes while plotting band structure from JSON

* Fix dispersion splitting, regions; allow user to set energy-range

- If we use the insert_gamma option to calculate_qpoint_phonon_modes,
  the split points from the input bandpath become incorrect. In order
  to guarantee the labels/split-points from seekpath, we inject the
  duplicate Gamma-points into band path data.

- Add --e-min, --e-max options

* euphonic-dispersion: update tests to reflect CLI argument changes

* rename neutron_band_structure -> intensity_map

This reflects a slightly broader scope, reading phonon mode data and
plotting heatmaps.

* import hackery to deal with old Pint versions

* Add DOS mode to euphonic-intensity-map, make this the default

* Test intensity-map; link broadening units to input arguments

The output image maps would add quite a few MB of data to the
repository, and we are looking to overhaul this with a proper image
comparison process at a later stage. For now, just take a few slices.

* Enable intensity-map to load q-point phonon mode data

A bit more refactoring and code-sharing between euphonic-dispersion
and euphonic-intensity-map means these now have essentially the same
front-end and can load the same input files.

* Add --v-min, --v-max arguments to intensity-map

* Add .hdf5, .yaml band data support to dispersion, intensity-map

- There is quite a bit of dispatching logic here that could use some
  proper testing.

- The logic may need refactoring when we support another format that
  uses .yaml or .hdf5.

* Argparse help updates: intensity-map, dispersion CLI

* Add --asr option to dispersion, intensity-map CLI; with tests.

Defaulting to no ASR correction because

- changes to data should be explicit
- and it's much easier to implement this way

* Increase tol on extent for intensity map tests

* Remove unused hashlib import

* Set energy units after modes have been created

* Move common args to cli utils

* Update euphonic-dos to read force constants

Also update it to be more consistent with dispersion and
intensity-map

* Update script test data

* Allow reading of a wider variety of phonopy files

Allow reading of renamed mesh/qpoints/bands.yaml/hdf5 and
force_constants.hdf5

* Refactor script tests

 - Put script arguments and output files in test file rather than utils
 - Enable regeneration of test data files via Pytest (as a test with
   skip turned on by default)

* Update script tests

- Test all arguments and their short versions
- Test most common combinations of arguments
- Test all types of file reads (.castep_bin, .phonon, .yaml, .hdf5...)
- Test save plot to file

* Add function to get key for script test outputs

Now that the input file is included in dos_args, dispersion_args etc.,
it cannot be used naively to produce a key with str.join, as this
includes the absolute path, which will be different on different
systems. Instead extract the directory name and filename and use those
in the key.

* Increase test tolerance if ASR present

Otherwise fails on CI machines

* Add CLI error tests

- Remove code paths that can't be reached
- Test appropriate errors are raised on incorrect inputs

* Make small changes from review comments

 - Set atol for test_dispersion in if/else
 - Catch runtime warning in calculate_dos and add test

* Update script data for new broadening

* Add tests for figure labels/title to script tests

* Make setting of 1D ax labels consitent with 2D

* Test dispersion data as a series of 2D arrays

Numpy can't automatically convert '3D' nested lists

* Explicitly use empty strings for plot labels

If left as None, older versions of Matplotlib set literal
'None' rather that having an empty label

* Test plotting module

Begin unit tests for _plot_1d_core

* Plotting module tests: _plot_1d_core from Spectrum1DCollection

* Plot tests: try old-fashioned add_subplot syntax

Seem to be having problems with tests on minimum requirements

* Plot tests: 1D tick labels

* Plot tests: simple plot_1d

* Plotting tests: test plot_dispersion; syntax tweak

We shouldn't offer to forward *args to plot_1d because

a) plot_1d doesn't take any extra positional args
b) this follows a named arg, which isn't allowed

* Plotting tests: matplotlib import error

- Instead of raising a warning and error simultaneously, customise the
  error message
- Be more specific: only ModuleNotFoundError should give message about
  installing matplotlib; other ImportError implies a different problem
- Test this using the same trick as missing phonopy test; mock the
  import builtin to fail on Matplotlib.

* Plotting: More 1D tests, a bit of cleanup

- Tweak the logic for subplots; instead of checking whether the plots
  were squeezed to a single axes, set squeeze=False to guarantee 2D
  array, then flatten() to guarantee 1D series.

- Context manager is unnecessary for patching with pytest-mock

- Add tests for plot_1d with multiple subplots

* Test euphonic.plot._plot_2d_core

- This has a lot in common with the corresponding script test, so some
  infrastructure is factored out and shared.

- Why test a private function? Well...
  - it makes it a lot easier to get complete coverage of plot_2d as we
    can now mock this function and just check it is called correctly
  - it probably won't be private forever, it's too useful

* Test main euphonic.plot.plot_2d function

* Plotting tests: axis tick labels utility function

* Plot tests: tweak to Normalize setting for robustnes with old mpl

* Test euphonic.plot.plot_2d with multiple segments

* Tweak xticklabel test for matplotlib version compatibility

* Just PEP8 things

* Remove plot_dispersion, update docs to teach .get_dispersion()

* Update plot_1d docs page

* plotting docs - small fixes

From @rebeccafair review comments

* Fix test for matplotlib import error

The imports were cleaned up, leading to import of 'matplotlib.pyplot'
but not 'matplotlib'. The new import mocker should be more robust,
working for 'matplotlib' or any 'matplotlib.*'

* Fix code block formatting in docs

* Make get_bin_centres/edges public and fix bugs

- Spectrum1DCollection was returning incorrect centres/edges because
  the y_data in this case is 2D, so the wrong axis size was being
  checked. Have fixed this with a refactor and added a RuntimeError
  for unexpected axis sizes to avoid this in the future
- get_bin_centres/edges for 1D now has no arguments, as
  this only makes sense for the x_axis. 2D still has bin_ax='x/y'
- Added docstrings describing methods and caveats

* Add tests for bin edges/centres RuntimeError

* Add missing test data files

* Remove unused Unit import from spectra.py

* Update plot_1d/2d_core to plot_1d/2d_to_axis

* Update docs

 - Update CL tool docs to mention force constants
 - Add docs for euphonic-intensity-map
 - Add sections on plot_1d/2d_to_axis
 - Add Spectrum1DCollection section
 - Add plotting dispersion link to QpointPhononModes
 - Remove outdated mention of refactor
 - Remove Jupyter notebook examples

* Add changelog to docs

* Update changelog

* Remove mention of btol in plot_1d docstring

* Fix changelog formatting

* Fix doc typo

* Small changes from PR review

 - Ensure old changelog entry for v0.2 -> v0.3 refactoring points
   to v0.3 documentation as the refactor.rst file has been deleted
 - Increase DOS grid size in doc euphonic-dos example
 - Change _is_bin_edge to raise ValueError instead of RuntimeError
 - Doc typo fixes

Co-authored-by: Rebecca Fair <[email protected]>
  • Loading branch information
ajjackson and rebeccafair authored Feb 8, 2021
1 parent 3531145 commit 0a24010
Show file tree
Hide file tree
Showing 78 changed files with 63,657 additions and 126,584 deletions.
36 changes: 29 additions & 7 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
`Unreleased <https://github.com/pace-neutrons/Euphonic/compare/v0.3.2...HEAD>`_
----------

- Changes:

- Some of Euphonic's dependency version requirements have been changed - but
- There have been some major changes and improvements to spectra, plotting
and command line tools, including:

- New command line tool ``euphonic-intensity-map`` for plotting weighted
2D Spectra e.g. Coherent neutron S(Q,w)
- Existing command line tools ``euphonic-dispersion`` and ``euphonic-dos``
have been updated to also read force constants and Phonopy files.
Arguments are also more consistent across tools so some may have changed,
check the command line tool help for details.
- New ``Spectrum1DCollection`` object for containing 1D spectra with a
shared x-axis (e.g. phonon dispersion modes)
- New ``plot_1d_to_axis`` and ``plot_2d_to_axis`` functions to allow
plotting on specific axes
- ``get_bin_centres`` and ``get_bin_edges`` utility functions on spectra
- The ``ratio`` argument to ``plot_2d`` has been removed, it should no longer
be required due to better management of relative axis sizes.
- The ``btol`` argument to ``plot_1d`` has been removed, it is recommended
to use ``Spectrum1D.split()`` or ``Spectrum1DCollection.split()`` instead.
- The ``plot_dispersion`` function has been removed. It is now recommended
to plot dispersion using ``plot_1d(QpointPhononModes.get_dispersion())``.
See docs for details.

- Other changes:

- Some of Euphonic's dependency version requirements have been changed, but
can now be relied on with more certainty due to better CI testing. This
includes:

Expand Down Expand Up @@ -112,17 +134,17 @@

- Breaking Changes:

- There has been a major refactor, for see the latest
`docs <https://euphonic.readthedocs.io/en/latest>`_ for how to use, or
`here <https://euphonic.readthedocs.io/en/latest/refactor.html>`_ for
- There has been a major refactor, for see the v0.3.0
`docs <https://euphonic.readthedocs.io/en/v0.3.0>`_ for how to use, or
`here <https://euphonic.readthedocs.io/en/v0.3.0/refactor.html>`_ for
refactor details
- Python 2 is no longer supported. Supported Python versions are ``3.6``,
``3.7`` and ``3.8``

- New Features:

- Euphonic can now read Phonopy input! See
`the docs <https://euphonic.readthedocs.io/en/latest>`_
`the docs <https://euphonic.readthedocs.io/en/v0.3.0>`_
for details.

- Improvements:
Expand Down
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Euphonic
========

Euphonic is a Python package that can efficiently calculate phonon
bandstructures and inelastic neutron scattering intensities from a force
constants matrix (e.g. from a .castep_bin file). Euphonic can also do
simple plotting, and can plot dispersion and density of states from
precalculated phonon frequencies (e.g. CASTEP .phonon).
bandstructures and inelastic neutron scattering intensities from a
force constants matrix (e.g. from a .castep_bin file). While Euphonic
is primarily a library, a command-line tool is provided for convenient
plotting of inelastic neutron scattering intensities from
force-constants data.

Euphonic can also plot previously-calculated dispersion and density of
states data from a CASTEP .phonon file.

For more information, see the `docs <http://euphonic.readthedocs.io/en/latest/>`_.
3 changes: 3 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. _changelog:

.. include:: ../../CHANGELOG.rst
16 changes: 12 additions & 4 deletions doc/source/disp-script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
euphonic-dispersion
===================

The ``euphonic-dispersion`` program can be used to plot precalculated
frequencies from a CASTEP ``.phonon`` file. For example, to plot from
a ``quartz.phonon`` file, run::
The ``euphonic-dispersion`` program can be used to plot dispersion
either along a specific trajectory from precalculated phonon frequencies,
or along a recommended reciprocal space path from force constants. For
example, to plot from a Euphonic ``.json`` file containing
`QpointPhononModes`, with frequencies reordered to follow equivalent modes
across Q, run::

euphonic-dispersion quartz.phonon
euphonic-dispersion --reorder si_qpoint_phonon_modes.json

Or, to plot along a recommended q-point path from Phonopy force constants
with an acoustic sum rule, run::

euphonic-dispersion --asr reciprocal phonopy.yaml

To see all the command line options, run::

Expand Down
12 changes: 9 additions & 3 deletions doc/source/dos-script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ euphonic-dos
============

The ``euphonic-dos`` program can be used to plot a density of states
from precalculated frequencies in a ``.phonon`` file. For example, to
plot DOS from a ``quartz.phonon`` file, run::
from precalculated frequencies, or on a specific Monkhorst-Pack grid
from force constants. For example, to plot DOS from a CASTEP ``.phonon``
file in units of 1/cm, run::

euphonic-dos quartz.phonon
euphonic-dos --energy-unit 1/cm quartz-554-grid.phonon

Or, to plot DOS from CASTEP force constants in a ``.castep_bin`` file
on a 15x15x12 grid with broadening, run::

euphonic-dos --grid 15 15 12 --energy-broadening 1.5 quartz.castep_bin

To see all the command line options, run::

Expand Down
33 changes: 33 additions & 0 deletions doc/source/intensity-map-script.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _intensity-map-script:

======================
euphonic-intensity-map
======================

The ``euphonic-intensity-map`` program can be used to plot a 2D intensity
map either along a specific trajectory from precalculated phonon frequencies
and eigenvectors, or along a recommended reciprocal space path from force
constants.

For example, to plot a coherent neutron-weighted intensity map from CASTEP
force constants along a recommended q-point path, one could run::

euphonic-intensity-map --weights coherent --energy-broadening 1.5 quartz.castep_bin

Or, to plot a DOS-weighted intensity from Phonopy phonon frequencies::

euphonic-intensity-map --weights dos --energy-unit THz --energy-broadening 0.15 band.yaml

To see all the command line options, run::

euphonic-intensity-map -h

You can also see the available command line options below

Command Line Options
--------------------

.. argparse::
:module: euphonic.cli.intensity_map
:func: get_parser
:prog: euphonic-intensity-map
131 changes: 111 additions & 20 deletions doc/source/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,128 @@ Plotting
========

Plotting in Euphonic is contained in a separate ``euphonic.plot`` module,
and all plotting functions return a ``matplotlib.figure.Figure``, which can
and most plotting functions return a ``matplotlib.figure.Figure``, which can
be tweaked, then viewed with ``matplotlib.figure.Figure.show()``

.. contents:: :local:

.. _plotting-dispersion:

Plotting Dispersion
===================

Phonon dispersion can be plotted straight from the q-points/frequencies in a
:ref:`QpointPhononModes <qpoint-phonon-modes>` object with
:py:meth:`euphonic.plot.plot_dispersion`. Extra arguments get passed to
:py:meth:`plot_1d <euphonic.plot.plot_dispersion>`, for adding axis labels
etc.:
Phonon dispersion can be plotted from the q-points/frequencies in
:ref:`QpointPhononModes <qpoint-phonon-modes>` using
:py:meth:`QpointPhononModes.get_dispersion <euphonic.qpoint_phonon_modes.QpointPhononModes.get_dispersion>`
to convert the frequencies into a :ref:`Spectrum1DCollection` object, which
is plotted with :py:meth:`euphonic.plot.plot_1d`. Converting to
:ref:`Spectrum1DCollection` creates a defined x-axis for the plot. Extra
arguments get passed to :py:meth:`plot_1d <euphonic.plot.plot_1d>`, for
adding axis labels etc.:

.. code-block:: py
from euphonic import QpointPhononModes
from euphonic.plot import plot_dispersion
from euphonic.plot import plot_1d
phonons = QpointPhononModes.from_castep('quartz.phonon')
fig = plot_dispersion(phonons, y_label='Energy (meV)')
bands = phonons.get_dispersion() # type: Spectrum1DCollection
fig = plot_1d(bands, y_label='Energy (meV)')
fig.show()
Docstring
---------
Phonon dispersion plots often include large steps between discontinuous
regions in reciprocal space. In order to accommodate this, a single
:ref:`Spectrum1D` or :ref:`Spectrum1DCollection` can be split into
a list of spectra with the :py:meth:`euphonic.spectra.Spectrum1D.split`
method. :py:meth:`plot_1d <euphonic.plot.plot_1d>` will happily accept
this list as input, plotting each region to a series of proportionally-spaced
subplots.

A compact recipe to write a band-structure plot with discontinuities could be

.. code-block:: py
from euphonic import QpointPhononModes
from euphonic.plot import plot_1d
phonons = QpointPhononModes.from_castep('quartz.phonon')
fig = plot_1d(phonons.get_dispersion().split())
fig.savefig('quartz-dispersion.pdf')
.. autofunction:: euphonic.plot.plot_dispersion
1D Plots
========

1D spectra are plotted with :py:meth:`euphonic.plot.plot_1d`. Multiple 1D
spectra can be plotted on the same axis by passing a list:
1D spectra are arranged in a matplotlib Figure with :py:meth:`euphonic.plot.plot_1d`.
For multiple lines on the same axes, use Spectrum1DCollection objects.
A sequence of Spectrum1D or Spectrum1DCollection objects will be interpreted
as a series of axis regions:

.. code-block:: py
from euphonic import Spectrum1D
from euphonic import Spectrum1D, Spectrum1DCollection
from euphonic.plot import plot_1d
dos = Spectrum1D.from_json_file('dos.json')
dos_broaden = Spectrum1D.from_json_file('dos_broaden.json')
fig = plot_1d([dos, dos_broaden], x_label='Energy (meV)', y_min=0,
labels=['dos', 'broadened dos'])
dos_collection = Spectrum1DCollection.from_spectra([dos, dos_broaden])
fig = plot_1d(dos_collection, x_label='Energy (meV)', y_min=0,
labels=['Density of states', 'Broadened'])
fig.show()
Docstring
Plotting to a specific axis
---------------------------

This can be used to have multiple subplots in the same figure, or to plot
multiple :ref:`Spectrum1D` objects on the same axis (for example if they
have different x_data values, so using a :ref:`Spectrum1DCollection` is not
possible). An example of plotting 2 DOS with different energy bins on the
same axis:

.. code-block:: py
import matplotlib.pyplot as plt
from euphonic import Spectrum1D
from euphonic.plot import plot_1d_to_axis
dos1 = Spectrum1D.from_json_file('dos_ebins1.json')
dos2 = Spectrum1D.from_json_file('dos_ebins2.json')
fig, ax = plt.subplots(1, 1)
plot_1d_to_axis(dos1, ax)
plot_1d_to_axis(dos2, ax)
fig.show()
An example of plotting 2 DOS on different axes on the same figure:

.. code-block:: py
import matplotlib.pyplot as plt
from euphonic import Spectrum1D
from euphonic.plot import plot_1d_to_axis
dos1 = Spectrum1D.from_json_file('dos_ebins1.json')
dos2 = Spectrum1D.from_json_file('dos_ebins2.json')
fig, axes = plt.subplots(1, 2)
plot_1d_to_axis(dos1, axes[0])
plot_1d_to_axis(dos2, axes[1])
fig.show()
Docstrings
---------

.. autofunction:: euphonic.plot.plot_1d

.. autofunction:: euphonic.plot.plot_1d_to_axis

2D Plots
========

2D spectra are plotted with :py:meth:`euphonic.plot.plot_2d`:
2D spectra are arranged in a matplotlib Figure with
:py:meth:`euphonic.plot.plot_2d`:

.. code-block:: py
Expand All @@ -70,7 +137,31 @@ Docstring
fig, ims = plot_2d(sqw, ratio=1.0)
fig.show()
Docstring
Plotting to a specific axis
---------------------------

This can be used to multiple subplots showing :ref:`Spectrum2D` in the same
figure. A `matplotlib.colors.Normalize` object can also be used to ensure both
spectra are on the same colour scale. An example of this for 2 S(Q,w) is below:

.. code-block:: py
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
from euphonic import Spectrum2D
from euphonic.plot import plot_2d_to_axis
sqw1 = Spectrum2D.from_json_file('sqw1.json')
sqw2 = Spectrum2D.from_json_file('sqw2.json')
norm = Normalize(vmin=0, vmax=1e-10)
fig, axes = plt.subplots(1, 2)
plot_2d_to_axis(sqw1, axes[0], norm=norm)
plot_2d_to_axis(sqw2, axes[1], norm=norm)
fig.show()
Docstrings
---------

.. autofunction:: euphonic.plot.plot_2d
.. autofunction:: euphonic.plot.plot_2d

.. autofunction:: euphonic.plot.plot_2d_to_axis
5 changes: 5 additions & 0 deletions doc/source/qpoint-phonon-modes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ This reordering can be seen the plotting dispersion (see
phonons = QpointPhononModes.from_castep('quartz.phonon')
phonons.reorder_frequencies()
Plotting Dispersion
-------------------

See :ref:`Plotting Dispersion <plotting-dispersion>`


Calculating The Coherent Neutron Structure Factor
-------------------------------------------------
Expand Down
46 changes: 0 additions & 46 deletions doc/source/refactor.rst

This file was deleted.

Loading

0 comments on commit 0a24010

Please sign in to comment.