Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Altair] Sync exported histogram code with new bin determination #304

Merged
merged 37 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
41df234
Merge upstream
micahtyong Jan 15, 2021
1a96a93
Merge remote-tracking branch 'upstream/master'
micahtyong Jan 16, 2021
3713b9e
Merge remote-tracking branch 'upstream/master'
micahtyong Feb 9, 2021
1eed196
Merge remote-tracking branch 'upstream/master'
Feb 10, 2021
dae2565
Merge remote-tracking branch 'upstream/master'
micahtyong Feb 16, 2021
f3b2963
Merge remote-tracking branch 'upstream/master'
micahtyong Feb 17, 2021
9e03a8c
Sync with master
micahtyong Feb 18, 2021
677a50e
Merge remote-tracking branch 'upstream/master'
micahtyong Feb 21, 2021
388b911
Merge remote-tracking branch 'upstream/master'
micahtyong Feb 22, 2021
b7158aa
Fix bin size variance from #217
micahtyong Feb 22, 2021
2a7a771
Format and test
micahtyong Feb 22, 2021
2228669
Change labelOverlap to True
micahtyong Feb 22, 2021
b322f1d
Modify markbar; currently questioning whether or not it's needed
micahtyong Feb 22, 2021
9cb9418
Remove markbar enitrely, rely on Altair automatic bin detection https…
micahtyong Feb 22, 2021
9216dba
Modify code snippet
micahtyong Feb 22, 2021
0956854
Revert "Remove markbar enitrely, rely on Altair automatic bin detecti…
micahtyong Feb 23, 2021
8e754a8
Merge remote-tracking branch 'upstream/master' into binned-charts
micahtyong Feb 27, 2021
436eff9
Implement bin size estimation via Freedman Diaconis's Rule
micahtyong Feb 27, 2021
2d84df3
Use numpy to compute IQR for better performance (pandas too slow)
micahtyong Mar 1, 2021
a1532e1
Add tests
micahtyong Mar 1, 2021
69ff784
Add test cases for histogram binning
micahtyong Mar 2, 2021
bb9724f
Address changes from @domoritz review (small optimizations)
micahtyong Mar 2, 2021
091670d
Black and format
micahtyong Mar 2, 2021
5b4643c
Move histogram bin width computation to pandas executor (execute_binn…
micahtyong Mar 2, 2021
9990b3c
Center bars between ticks in distribution setting
micahtyong Mar 2, 2021
395fc14
Renaming in execute_binning
micahtyong Mar 2, 2021
86ee855
Bin width computed accurately in execute_binning; no need for get_bin…
micahtyong Mar 3, 2021
5794cb5
Revert to Freedman rule; maintain correct ticks
micahtyong Mar 3, 2021
7e206b5
Format and merge
micahtyong Mar 3, 2021
b37a3d4
Merge branch 'master' of https://github.com/lux-org/lux
micahtyong Mar 3, 2021
1ca9df8
Merge remote-tracking branch 'upstream/master'
micahtyong Mar 6, 2021
33e43e9
Merge remote-tracking branch 'upstream/master'
micahtyong Mar 13, 2021
14b388a
Merge branch 'master' of https://github.com/micahtyong/lux into binne…
micahtyong Mar 13, 2021
c21b936
Sync exported code with new histogram bin determination rules
micahtyong Mar 13, 2021
049fed7
Sync exported code with new histogram bin determination rules
micahtyong Mar 13, 2021
1c1e629
Merge branch 'binned-charts' of https://github.com/micahtyong/lux int…
micahtyong Mar 13, 2021
86eaac2
Modify histogram code test case
micahtyong Mar 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lux/vislib/altair/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def initialize_chart(self):
y=alt.Y(
str(msr_attr.attribute),
title=axis_title,
bin=alt.Bin(binned=True, step=markbar),
bin=alt.Bin(binned=True, step=step),
type=msr_attr.data_type,
axis=alt.Axis(title=axis_title),
),
y2=end_attr_abv,
Expand All @@ -99,20 +100,21 @@ def initialize_chart(self):
#####################################

self.code += "import altair as alt\n"
# self.code += f"visData = pd.DataFrame({str(self.data.to_dict(orient='records'))})\n"
self.code += f"visData = pd.DataFrame({str(self.data.to_dict())})\n"
if measure.channel == "x":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
alt.X('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))),
alt.Y("Number of Records", type="quantitative")
chart = alt.Chart(visData).mark_bar().encode(
x=alt.X('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True, step={step}), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))),
x2='{end_attr_abv}',
y=alt.Y("Number of Records", type="quantitative")
)
"""
elif measure.channel == "y":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
alt.Y('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))),
alt.X("Number of Records", type="quantitative")
chart = alt.Chart(visData).mark_bar().encode(
y=alt.Y('{msr_attr.attribute}', title='{axis_title}', bin=alt.Bin(binned=True, step={step}), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}')),
y2='{end_attr_abv}',
x=alt.X("Number of Records", type="quantitative")
)
"""
return chart
Expand Down
5 changes: 1 addition & 4 deletions tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import pandas as pd
from lux.vis.VisList import VisList
from lux.vis.Vis import Vis
from lux.vislib.altair.Histogram import compute_bin_width


def test_vis(global_var):
Expand Down Expand Up @@ -341,11 +340,9 @@ def test_histogram_chart(global_var):
lux.config.plotting_backend = "vegalite"
vis = Vis(["Displacement"], df)
vis_code = vis.to_Altair()
expected_bin_size = compute_bin_width(vis.data["Displacement"])
assert "alt.Chart(visData).mark_bar" in vis_code
assert str(expected_bin_size) in vis_code
assert (
"alt.X('Displacement', title='Displacement (binned)',bin=alt.Bin(binned=True), type='quantitative', axis=alt.Axis(labelOverlap=True, title='Displacement (binned)'), scale=alt.Scale(domain=(68.0, 455.0)))"
"alt.X('Displacement', title='Displacement (binned)',bin=alt.Bin(binned=True, step=38.7), type='quantitative', axis=alt.Axis(labelOverlap=True, title='Displacement (binned)'), scale=alt.Scale(domain=(68.0, 455.0)))"
in vis_code
)
assert 'alt.Y("Number of Records", type="quantitative")' in vis_code
Expand Down