PLOTS View1dΒΆ

# -*-Python-*-
# Created by smithsp at 11 Jul 2018  11:44

"""
This script demonstrates the use of View1d

Contents extracted/reordered from regression/test_OMFITplot.py
"""

# basic View1d test from docstring

# set up data
fig = plt.figure('Test View1d()')
t = arange(20)
s = linspace(0, 2 * np.pi, 60)
y = np.sin(atleast_2d(s).T + atleast_2d(t))
da = xarray.DataArray(y, coords=SortedDict([('space', s), ('time', t)]), name='sine', dims=['space', 'time'])

# draw sin
v = View1d(da, dim='space', time=10)

# For uncertainties arrays, it draws errorbars using the uerrorbar function.
# Multiple views with the same dimensions can be linked for increased speed (eliminate redundant calls to redraw).
from pylab import random

y_u = unumpy.uarray(y + (random(y.shape) - 0.5), random(y.shape))
da_u = xarray.DataArray(y_u, coords=SortedDict([('space', s), ('time', t)]), name='measured', dims=['space', 'time'])
v_u = View1d(da_u, dim='space', time=10, axes=gca())
v.link(v_u)  # v will remain connected to keypress events and drive vu

# Variable dependent axis data can be viewed if x and y share a regular grid in some coordinates,
x = array([s + (random(s.shape) - 0.5) * 0.2 for i in t]).T
da_x = xarray.DataArray(x, coords=SortedDict([('space', s), ('time', t)]), name='varspace', dims=['space', 'time'])
ds = da_u.to_dataset().merge(da_x.to_dataset())
v_x = View1d(ds, name='measured', dim='varspace', time=10, axes=gca())
v.link(v_x)

# test keyboard controls
class FakeEvent(object):
    key = None


e = FakeEvent()
for key in ['right', 'up', 'w', 'left', 'down', 'e']:
    e.key = key
    v.key_command(e)