Skip to content

Commit

Permalink
Merge pull request #33 from wgurecky/fix_seaborn_stat_func
Browse files Browse the repository at this point in the history
remove use of depreciated stat_func in seaborn plot
  • Loading branch information
wgurecky committed Oct 17, 2020
2 parents 4ae8ba3 + f560fd9 commit b952a88
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion starvine/bvcopula/bv_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def bvJointPlot(u, v, corr_stat="kendalltau", vs=None, **kwargs):
"spearmanr": spearmanr,
"pearsonr": pearsonr}
outfile = kwargs.pop("savefig", None)
joint_plt = sns.jointplot(x=u, y=v, stat_func=stat_funcs[corr_stat], zorder=2, label="resampled", **kwargs)
joint_plt = sns.jointplot(x=u, y=v, zorder=2, label="resampled", **kwargs)
# joint_plt.annotate(stat_funcs[corr_stat])
vsData = vs
if vsData is not None:
joint_plt.x, joint_plt.y = vsData[0], vsData[1]
Expand Down
4 changes: 2 additions & 2 deletions starvine/bvcopula/tests/test_gauss_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def testGaussRotate(self):
for rotation, shapeParam in iteritems(shapes):
gauss = Copula("gauss", 0)
u, v = gauss.sample(10000, *(shapeParam,))
g = sns.jointplot(u, v, stat_func=kendalltau)
g = sns.jointplot(u, v)
g.savefig("gauss_sample_pdf_" + str(rotation) + ".png")
gauss.fittedParams = (shapeParam,)
c_kTau = gauss.kTau()
Expand All @@ -43,5 +43,5 @@ def testGaussRotate(self):
self.assertAlmostEqual(c_kTau, gauss_refit.copulaModel.kTau(), delta=0.05)
self.assertAlmostEqual(shapeParam, gauss_refit.copulaParams[1][0], delta=0.2)
# plot resampled data
g_resample = sns.jointplot(u_resample, v_resample, stat_func=kendalltau)
g_resample = sns.jointplot(u_resample, v_resample)
g_resample.savefig("gauss_resample_pdf_" + str(rotation) + ".png")
4 changes: 2 additions & 2 deletions starvine/bvcopula/tests/test_rotation_clayton.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def testClaytonRotate(self):
for rotation, expectedKtau in iteritems(expectedKtaus):
clayton = Copula("clayton", rotation)
u, v = clayton.sample(40000, *(shapeParam,))
g = sns.jointplot(u, v, stat_func=kendalltau)
g = sns.jointplot(u, v)
g.savefig("clayton_sample_pdf_" + str(rotation) + ".png")
clayton.fittedParams = (shapeParam,)
c_kTau = clayton.kTau()
Expand All @@ -58,5 +58,5 @@ def testClaytonRotate(self):
u_resample, v_resample = clayton_refit.copulaModel.sample(1000)
self.assertAlmostEqual(c_kTau, clayton_refit.copulaModel.kTau(), delta=0.05)
# plot resampled data
g_resample = sns.jointplot(u_resample, v_resample, stat_func=kendalltau)
g_resample = sns.jointplot(u_resample, v_resample)
g_resample.savefig("clayton_resample_pdf_" + str(rotation) + ".png")
4 changes: 2 additions & 2 deletions starvine/bvcopula/tests/test_rotation_frank.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def testFrankRotate(self):
for rotation, expectedKtau in iteritems(expectedKtaus):
frank = Copula("frank", rotation)
u, v = frank.sample(10000, *(shapeParam,))
g = sns.jointplot(u, v, stat_func=kendalltau)
g = sns.jointplot(u, v)
g.savefig("frank_sample_pdf_" + str(rotation) + ".png")
frank.fittedParams = (shapeParam,)
c_kTau = frank.kTau()
Expand All @@ -53,5 +53,5 @@ def testFrankRotate(self):
u_resample, v_resample = frank_refit.copulaModel.sample(1000)
self.assertAlmostEqual(c_kTau, frank_refit.copulaModel.kTau(), delta=0.05)
# plot resampled data
g_resample = sns.jointplot(u_resample, v_resample, stat_func=kendalltau)
g_resample = sns.jointplot(u_resample, v_resample)
g_resample.savefig("frank_resample_pdf_" + str(rotation) + ".png")
4 changes: 2 additions & 2 deletions starvine/bvcopula/tests/test_rotation_gumbel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def testGumbelRotate(self):
for rotation, expectedKtau in iteritems(expectedKtaus):
gumbel = Copula("gumbel", rotation)
u, v = gumbel.sample(40000, *(shapeParam,))
g = sns.jointplot(u, v, stat_func=kendalltau)
g = sns.jointplot(u, v)
g.savefig("gumbel_sample_pdf_" + str(rotation) + ".png")
gumbel.fittedParams = (shapeParam,)
c_kTau = gumbel.kTau()
Expand All @@ -52,5 +52,5 @@ def testGumbelRotate(self):
u_resample, v_resample = gumbel_refit.copulaModel.sample(4000)
self.assertAlmostEqual(c_kTau, gumbel_refit.copulaModel.kTau(), delta=0.05)
# plot resampled data
g_resample = sns.jointplot(u_resample, v_resample, stat_func=kendalltau)
g_resample = sns.jointplot(u_resample, v_resample)
g_resample.savefig("gumbel_resample_pdf_" + str(rotation) + ".png")
12 changes: 6 additions & 6 deletions starvine/bvcopula/tests/test_t_copula_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def testTcoplulaFit(self):

# plot dataset for visual inspection
marg_dict = {}
plt0 = sns.jointplot(x, y, marginal_kws=marg_dict, stat_func=kendalltau)
plt0 = sns.jointplot(x, y, marginal_kws=marg_dict)
plt0.savefig("original_stocks.png")
bvPairPlot(x, y, savefig="original_stocks_pair.png")

# Rank transform the data
u = rankdata(x) / (len(x) + 1)
v = rankdata(y) / (len(y) + 1)
plt1 = sns.jointplot(u, v, marginal_kws=marg_dict, stat_func=kendalltau)
plt1 = sns.jointplot(u, v, marginal_kws=marg_dict)
plt1.savefig("rank_transformed.png")

# CDF tranformed data
Expand All @@ -49,7 +49,7 @@ def testTcoplulaFit(self):
for i, (xp, yp) in enumerate(zip(x, y)):
u_c[i] = kde_x.integrate_box_1d(-np.inf, xp)
v_c[i] = kde_y.integrate_box_1d(-np.inf, yp)
plt11 = sns.jointplot(u_c, v_c, marginal_kws=marg_dict, stat_func=kendalltau)
plt11 = sns.jointplot(u_c, v_c, marginal_kws=marg_dict)
plt11.savefig("cdf_transformed.png")

# Fit t copula and gaussian copula
Expand All @@ -74,13 +74,13 @@ def testTcoplulaFit(self):
# Sample from the fitted gaussian copula and plot
ug_hat, vg_hat = g_copula.sample(1000, *theta_g_fit)
pl.figure(2)
plt2 = sns.jointplot(ug_hat, vg_hat, stat_func=kendalltau)
plt2 = sns.jointplot(ug_hat, vg_hat)
plt2.savefig("gaussian_copula_hat.png")

# Sample from the fitted t copula and plot
ut_hat, vt_hat = t_copula.sample(1000, *theta_t_fit)
pl.figure(3)
plt3 = sns.jointplot(ut_hat, vt_hat, stat_func=kendalltau)
plt3 = sns.jointplot(ut_hat, vt_hat)
plt3.savefig("t_copula_hat.png")

# Resample original data
Expand All @@ -99,7 +99,7 @@ def icdf_uv_bisect(ux, X):
return icdf
resampled_x = icdf_uv_bisect(x, ut_hat)
resampled_y = icdf_uv_bisect(y, vt_hat)
plt5 = sns.jointplot(resampled_x, resampled_y, stat_func=kendalltau)
plt5 = sns.jointplot(resampled_x, resampled_y)
plt5.savefig("resampled_scatter.png")

# Compare to expected results
Expand Down

0 comments on commit b952a88

Please sign in to comment.