Skip to content

Commit

Permalink
FIX-#415: Default to Sturges' rule for histograms with few data points (
Browse files Browse the repository at this point in the history
#446)

* Use altair/Choropleth.py in MatpltlibRenderer.py to render choropleths; include warning

* sync

* Revert "sync"

This reverts commit a2c46e7.

* FIX-#415: Default to Sturges' rule for histograms with few data points
Signed-off-by: Micah Yong <micahtyong@gmail.com>

* FIX-#415: Default to Sturges' rule for histograms with few data points
Signed-off-by: Micah Yong <micahtyong@gmail.com>

* FIX-#415: Pass test_pandas testing by removing math.ceil

Signed-off-by: Micah Yong <micahtyong@gmail.com>
  • Loading branch information
micahtyong committed Jan 19, 2022
1 parent 4abee66 commit 726eaca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lux/vislib/altair/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from lux.vislib.altair.AltairChart import AltairChart
import altair as alt
import math

alt.data_transformers.disable_max_rows()

Expand Down Expand Up @@ -51,10 +52,10 @@ def initialize_chart(self):
markbar = compute_bin_width(self.data[msr_attr.attribute])
step = abs(self.data[msr_attr.attribute][1] - self.data[msr_attr.attribute][0])

# Default when bin too small
# Default to Sturges' Rule variant when bin too small
if markbar < (x_range / 24):
markbar = x_max - x_min / 12

bin_count = len(self.vis._source) ** (1 / 2)
markbar = 1.38 * x_range / bin_count
self.data = AltairChart.sanitize_dataframe(self.data)
end_attr_abv = str(msr_attr.attribute) + "_end"
self.data[end_attr_abv] = self.data[str(msr_attr.attribute)] + markbar
Expand Down Expand Up @@ -125,7 +126,6 @@ def compute_bin_width(series):
Helper function that returns optimal bin size via Freedman Diaconis's Rule
Source: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
"""
import math
import numpy as np

data = np.asarray(series)
Expand Down

0 comments on commit 726eaca

Please sign in to comment.