From c95e8c512db6eec9381cbc51074be2986d9e8659 Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 11 Nov 2019 11:48:14 -0600 Subject: Slope for correlation scatterplot now displays as scientific notation if it's too small to display as 3 decimal places --- wqflask/wqflask/correlation/corr_scatter_plot.py | 12 ++++++++++++ wqflask/wqflask/templates/corr_scatterplot.html | 13 ++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py index 07aa947e..e7fe8b91 100644 --- a/wqflask/wqflask/correlation/corr_scatter_plot.py +++ b/wqflask/wqflask/correlation/corr_scatter_plot.py @@ -38,6 +38,11 @@ class CorrScatterPlot(object): self.data.append(vals_2) slope, intercept, r_value, p_value, std_err = stats.linregress(vals_1, vals_2) + + if slope < 0.001: + slope_string = '%.3E' % slope + else: + slope_string = str(slope) x_buffer = (max(vals_1) - min(vals_1))*0.1 y_buffer = (max(vals_2) - min(vals_2))*0.1 @@ -54,6 +59,11 @@ class CorrScatterPlot(object): self.rdata.append(ry.tolist()) srslope, srintercept, srr_value, srp_value, srstd_err = stats.linregress(rx, ry) + if srslope < 0.001: + srslope_string = '%.3E' % srslope + else: + srslope_string = str(srslope) + x_buffer = (max(rx) - min(rx))*0.1 y_buffer = (max(ry) - min(ry))*0.1 @@ -90,11 +100,13 @@ class CorrScatterPlot(object): sr_intercept_coords = sr_intercept_coords, slope = slope, + slope_string = slope_string, intercept = intercept, r_value = r_value, p_value = p_value, srslope = srslope, + srslope_string = srslope_string, srintercept = srintercept, srr_value = srr_value, srp_value = srp_value diff --git a/wqflask/wqflask/templates/corr_scatterplot.html b/wqflask/wqflask/templates/corr_scatterplot.html index 545c0b94..a8d65169 100644 --- a/wqflask/wqflask/templates/corr_scatterplot.html +++ b/wqflask/wqflask/templates/corr_scatterplot.html @@ -145,7 +145,7 @@ Slope - {{'%0.3f' % jsdata.slope}} + {{ jsdata.slope_string }} Intercept @@ -163,7 +163,7 @@ Regression Line
- y = {{'%0.3f' % jsdata.slope}} * x + {{'%0.3f' % jsdata.intercept}} + y = {{ jsdata.slope_string }} * x + {{'%0.3f' % jsdata.intercept}} @@ -260,7 +260,7 @@ Slope - {{'%0.3f' % jsdata.srslope}} + {{ jsdata.srslope_string }} Intercept @@ -274,6 +274,13 @@ P value {% if jsdata.srp_value < 0.001 %}{{'%0.3e' % jsdata.srp_value}}{% else %}{{'%0.3f' % jsdata.srp_value}}{% endif %} + + + Regression Line +
+ y = {{ jsdata.srslope_string }} * x + {{'%0.3f' % jsdata.srintercept}} + + -- cgit v1.2.3