Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19ee6c3
commit e643385
Showing
3 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
.. currentmodule:: gwpy.plot | ||
|
||
.. _gwpy-plot-colorbars: | ||
|
||
######### | ||
Colorbars | ||
######### | ||
|
||
====================================== | ||
Modifications to the built-in colorbar | ||
====================================== | ||
|
||
GWpy extends the built-in :mod:`matplotlib` | ||
:meth:`~matplotlib.figure.Figure.colorbar` functionality to improve the | ||
defaults in a number of ways: | ||
|
||
- callable from the :class:`~matplotlib.figure.Figure`, or directly from the | ||
relevant :class:`~matplotlib.axes.Axes` | ||
- don't resize the anchor :class:`~matplotlib.axes.Axes` | ||
- simpler specification of log-norm colors | ||
- better log-scale ticks | ||
|
||
See the following example for a summary of the improvements: | ||
|
||
.. plot:: | ||
:include-source: | ||
|
||
import numpy | ||
data = numpy.random.rand(100, 100) | ||
from gwpy.timeseries import TimeSeries | ||
from matplotlib import pyplot | ||
fig, axes = pyplot.subplots(nrows=3, figsize=(6.4, 8)) | ||
for ax in axes: # plot the same data on each | ||
ax.imshow(data) | ||
fig.colorbar(axes[1].images[0], ax=axes[1]) # matplotlib default | ||
axes[2].colorbar() # gwpy colorbar | ||
pyplot.show() | ||
|
||
============================ | ||
Logarithmic colorbar scaling | ||
============================ | ||
|
||
With GWpy, getting logarithmic scaling on a colorbar is as simple as | ||
specifying, ``norm='log'``: | ||
|
||
.. plot:: | ||
:include-source: | ||
|
||
from gwpy.timeseries import TimeSeries | ||
data = TimeSeries.fetch_open_data('L1', 1187008866, 1187008898, tag='C00') | ||
specgram = data.spectrogram2(fftlength=.5, overlap=.25, | ||
window='hann') ** (1/2.) | ||
plot = specgram.plot(yscale='log', ylim=(30, 1400)) | ||
plot.colorbar(norm='log', clim=(1e-24, 1e-21), label='Strain ASD') | ||
plot.show() | ||
|
||
.. note:: | ||
|
||
Log-scales can also be specified using :class:`~matplotlib.colors.LogNorm` | ||
|
||
=============== | ||
Another example | ||
=============== | ||
|
||
.. plot:: | ||
:include-source: | ||
|
||
# load data | ||
from gwpy.timeseries import TimeSeries | ||
raw = TimeSeries.fetch_open_data('L1', 1126259446, 1126259478) | ||
|
||
# calculate filtered timeseries, and Q-transform spectrogram | ||
data = raw.bandpass(50, 300).notch(60).crop(1126259446+1) | ||
qtrans = raw.q_transform() | ||
|
||
# plot | ||
from matplotlib import pyplot | ||
plot, axes = pyplot.subplots(nrows=2, sharex=True, figsize=(8, 6)) | ||
tax, qax = axes | ||
tax.plot(data, color='gwpy:ligo-livingston') | ||
qax.imshow(qtrans) | ||
tax.set_xlabel('') | ||
tax.set_xscale('auto-gps') | ||
tax.set_xlim(1126259462.2, 1126259462.5) | ||
tax.set_ylabel('Strain amplitude') | ||
qax.set_yscale('log') | ||
qax.set_ylabel('Frequency [Hz]') | ||
qax.colorbar(clim=(0, 35), label='Normalised energy') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
.. currentmodule:: gwpy.plot.gps | ||
|
||
.. _gwpy-plot-gps: | ||
|
||
######################## | ||
Plotting GPS time scales | ||
######################## | ||
|
||
As we have seen, the default :mod:`matplotlib` representation of GPS scales | ||
is not great, given the large zero-offset typically seen with 21st century GPS | ||
times. | ||
|
||
To improve displays of data with GPS timestamps, GWpy provides a number of | ||
custom :mod:`scales <mtplotlib.scale>`. | ||
Each scale uses an ``epoch`` and a ``unit`` to recentre and format the GPS | ||
axis in a way that clearly displays the data, without large offsets or | ||
multipliers. | ||
|
||
============== | ||
``'auto-gps'`` | ||
============== | ||
|
||
The ``'auto-gps'`` scale (the default for most GPS-based plots) automatically | ||
calculates an ``epoch`` and ``unit`` each time the figure is drawn, based on | ||
the current view limits and data limits: | ||
|
||
.. plot:: | ||
:include-source: | ||
:context: reset | ||
|
||
>>> from gwpy.timeseries import TimeSeries | ||
>>> raw = TimeSeries.fetch_open_data('L1', 1126259446, 1126259478) | ||
>>> data = raw.bandpass(50, 300).notch(60).crop(1126259446+1) | ||
>>> plot = data.plot(xscale='auto-gps') | ||
>>> plot.show() | ||
|
||
Here the default epoch is just the epoch for the given `TimeSeries`, and the | ||
unit has been automatically chosen as ``'seconds'``. | ||
However, if we zoom the axes to a tiny fraction of a second, the ``unit`` is | ||
automatically reselected to something more sensible: | ||
|
||
.. plot:: | ||
:include-source: | ||
:context: | ||
|
||
>>> ax = plot.gca() | ||
>>> ax.set_xlim(1126259462.415, 1126259462.425) | ||
>>> plot.refresh() | ||
|
||
=========== | ||
Fixed units | ||
=========== | ||
|
||
A GPS axis can be fixed to a specific unit via the | ||
:meth:`~matplotlib.axes.Axes.set_xscale` (or | ||
:meth:`~matplotlib.axes.Axes.set_yscale`) method of the relevant axis. | ||
|
||
The available units are | ||
|
||
- ``'nanoseconds'`` | ||
- ``'microseconds'`` | ||
- ``'milliseconds'`` | ||
- ``'seconds'`` | ||
- ``'minutes'`` | ||
- ``'hours'`` | ||
- ``'days'`` | ||
- ``'weeks'`` | ||
- ``'years'`` | ||
|
||
.. plot:: | ||
:include-source: | ||
:context: | ||
|
||
>>> ax.set_xscale('seconds') | ||
>>> plot.refresh() | ||
|
||
=========== | ||
Fixed epoch | ||
=========== | ||
|
||
A GPS axis can be fixed to a specific epoch via the same | ||
:meth:`~matplotlib.axes.Axes.set_xscale` (or | ||
:meth:`~matplotlib.axes.Axes.set_yscale`) method of the relevant axis, or | ||
via the special :meth:`~gwpy.plot.Axes.set_epoch` method: | ||
|
||
.. plot:: | ||
:include-source: | ||
:context: | ||
|
||
>>> ax.set_xlim(1126259462.2, 1126259462.6) | ||
>>> ax.set_epoch(1126259462.42) | ||
>>> plot.refresh() | ||
|
||
.. note:: | ||
|
||
A fixed epoch can be used with ``'auto-gps'`` as well as any of the | ||
fixed units. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters