import psyplot.project as psy
import xarray as xr
%matplotlib inline
%config InlineBackend.close_figures = False
import numpy as np

x2 = np.arange(0, 2 * np.pi, .2)
y2 = np.arange(0, 2 * np.pi, .2)
x22d, y22d = np.meshgrid(x2, y2)
ds2 = xr.Dataset(
    {'u': xr.Variable(('x', 'y'), np.cos(x22d)),
     'v': xr.Variable(('x', 'y'), np.sin(y22d))},
    {'x': xr.Variable(('x', ), x2),
     'y': xr.Variable(('y', ), y2)})

"""
Explanation: Vector plot
Demonstration of the plotting of 2D vectors
The vector plotmethod uses matplotlibs quiver and streamplot
functions to create the plot. This plot method requires two variables: 'u' 
for the wind in x-direction, 'v' for the wind in y-direction.
Note that this method is extended by the mapvector plot method of the psy-maps plugin for visualization on the projected globe.
End of explanation
"""


p = psy.plot.vector(ds2, name=[['u', 'v']], arrowsize=20.0)

"""
Explanation: The default is a quiver plot
End of explanation
"""


p.update(cmap='Reds', color='absolute')
p.show()

"""
Explanation: You can also apply a colormap to the vectors via the colors formatoption. 
This can be one on 'u' (to use the x-direction), 'v' (to use
the 'y'-direction) or 'absolute' to use the absolute length of the
arrows.
End of explanation
"""


p.update(plot='stream', arrowsize=1.0)
p.show()

"""
Explanation: The vector plot method also supports stream plots through the plot
formatoption.
End of explanation
"""


p.summaries('vector')

psy.close('all')

"""
Explanation: The main formatoptions for the vector plots are in the vector group
End of explanation
"""


