# -*-Python-*-
# Created by bgrierson at 21 Mar 2018 12:28
"""
This script shows how to use a seaborn jointplot to put histograms on scatter plots
"""
import seaborn as sns
from pylab import random
defaultVars(kw1=None)
# A sin function and another function on the t axis
nt = 101
t = linspace(0, 1, 101) + 0.1 * random(nt)
y = np.sin(2.0 * np.pi * t) + 0.1 * random(nt)
z = y ** 2
# The data as an xarray DataArray
y_da = xarray.DataArray(y, coords=[('t', t)])
z_da = xarray.DataArray(z, coords=[('t', t)])
# Insert into an xarray Dataset
ds = xarray.Dataset()
ds['y'] = y_da
ds['z'] = z_da
# Convert to a pandas dataframe
df = ds.to_dataframe()
# Make a couple of different plots
fig, ax = plt.subplots()
# Regular plot
ax.plot(t, y, marker='o')
# Overplot using the DataArray plot method
y_da.plot(ax=ax)
# Use the dataframe plot method
df.plot(y='y', color='k')
# Use the dataframe scatter method
df.plot.scatter(x='y', y='z', c='z')
# Use the seaborn jointplot with histograms
sns.jointplot(x='t', y='y', data=ds, alpha=0.5, s=100.0)