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

test(rect): reproduce unemployment rect plot from bokeh docs #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions Tests/test_PandasBokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ def df_mapplot():
return df_mapplot


@pytest.fixture(scope="function")
def df_unemployment():
from bokeh.sampledata.unemployment1948 import data

data['Year'] = data['Year'].astype(str)
data = data.set_index('Year')
data.drop('Annual', axis=1, inplace=True)
data.columns.name = 'Month'

# reshape to 1D array or rates with a month and year for each row.
df = pd.DataFrame(data.stack(), columns=['rate']).reset_index()

return df


##############################################################################
##################################TESTS#######################################
##############################################################################
Expand Down Expand Up @@ -765,3 +780,30 @@ def test_autosizing(df_fruits):
pandas_bokeh.save(p_autoscale)

assert True


def test_rectplot(df_unemployment):
"Rectplot test"

kwargs = dict(
x="Year",
y="Month",
width=1,
height=1,
category="rate",
line_color=None,
show_figure=False,
)

p_rect = df_unemployment.plot_bokeh(kind="rect", **kwargs)
p_rect_accessor = df_unemployment.plot_bokeh.rect(**kwargs)

p_rect_pandas_backend = df_unemployment.plot(kind="rect", **kwargs)
p_rect_accessor_pandas_backend = df_unemployment.plot.map(**kwargs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouod be df_unemployment.plot_bokeh.rect


layout = pandas_bokeh.plot_grid(
[[p_rect, p_rect_accessor]], plot_width=450, plot_height=300, show_plot=False
)

pandas_bokeh.output_file(os.path.join(DIRECTORY, "Plots", "Rectplot.html"))
pandas_bokeh.save(layout)
17 changes: 17 additions & 0 deletions pandas_bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def plot(
"area",
"pie",
"map",
"rect",
]

rangetool_allowed_kinds = ["line", "step"]
Expand Down Expand Up @@ -851,6 +852,22 @@ def plot(
**kwargs,
)

if kind == "rect":

p = rectplot(
p,
source,
data_cols,
category,
category_values,
colormap,
hovertool,
hovertool_string,
figure_options,
xlabelname,
**kwargs,
)

# Set xticks:
if not xticks is None:
p.xaxis[0].ticker = list(xticks)
Expand Down