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

Added axis name for unnamed Series visualization #263

Merged
merged 8 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions lux/vislib/altair/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ def initialize_chart(self):
markbar = x_range / plot_range * 12

self.data = AltairChart.sanitize_dataframe(self.data)

axis_title = f"{msr_attr_abv} (binned)"
if msr_attr.attribute == " ":
axis_title = "Series (binned)"
if measure.channel == "x":
chart = (
alt.Chart(self.data)
.mark_bar(size=markbar)
.encode(
alt.X(
str(msr_attr.attribute),
title=f"{msr_attr.attribute} (binned)",
title=axis_title,
bin=alt.Bin(binned=True),
type=msr_attr.data_type,
axis=alt.Axis(labelOverlap=True, title=f"{msr_attr_abv} (binned)"),
axis=alt.Axis(labelOverlap=True, title=axis_title),
scale=alt.Scale(domain=(x_min, x_max)),
),
alt.Y("Number of Records", type="quantitative"),
Expand All @@ -79,9 +83,9 @@ def initialize_chart(self):
x=alt.X("Number of Records", type="quantitative"),
y=alt.Y(
str(msr_attr.attribute),
title=f"{msr_attr.attribute} (binned)",
title=axis_title,
bin=alt.Bin(binned=True),
axis=alt.Axis(labelOverlap=True, title=f"{msr_attr_abv} (binned)"),
axis=alt.Axis(labelOverlap=True, title=axis_title),
scale=alt.Scale(domain=(x_min, x_max)),
),
)
Expand All @@ -96,14 +100,14 @@ def initialize_chart(self):
if measure.channel == "x":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
alt.X('{msr_attr.attribute}', title='{msr_attr.attribute} (binned)',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{msr_attr_abv} (binned)'), scale=alt.Scale(domain=({x_min}, {x_max}))),
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")
)
"""
elif measure.channel == "y":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
alt.Y('{msr_attr.attribute}', title='{msr_attr.attribute} (binned)',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{msr_attr_abv} (binned)'), scale=alt.Scale(domain=({x_min}, {x_max}))),
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")
)
"""
Expand Down
7 changes: 5 additions & 2 deletions lux/vislib/matplotlib/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ def initialize_chart(self):

x_label = ""
y_label = ""
axis_title = f"{msr_attr_abv} (binned)"
if msr_attr_abv == " ":
axis_title = "Series (binned)"
if measure.channel == "x":
x_label = f"{msr_attr.attribute} (binned)"
x_label = axis_title
y_label = "Number of Records"
elif measure.channel == "y":
x_label = "Number of Records"
y_label = f"{msr_attr.attribute} (binned)"
y_label = axis_title

self.ax.set_xlabel(x_label)
self.ax.set_ylabel(y_label)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,20 @@ def test_series_recommendation():
df.plot_config = None
df = df["YearsAtCompany"] / df["TotalWorkingYears"]
assert len(df.recommendation["Distribution"]) > 0, "Recommendation property empty for LuxSeries"


def test_unnamed_column():
lux.config.plotting_backend = "matplotlib"
df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv")
lux.config.plotting_style = None
series = df["YearsAtCompany"] / df["TotalWorkingYears"]
series.__repr__()
axis_title = "Series (binned)"
exported_code_str = series.recommendation["Distribution"][0].to_matplotlib_code()
assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder"

lux.config.plotting_backend = "vegalite"
series = df["YearsAtCompany"] / df["TotalWorkingYears"]
series.__repr__()
exported_code_str = series.recommendation["Distribution"][0].to_Altair()
assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder"