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

Add step plot #27

Merged
merged 1 commit into from
Jun 24, 2019
Merged
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
136 changes: 134 additions & 2 deletions pandas_bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def plot(
# Check plot kind input:
allowed_kinds = [
"line",
"step",
"point",
"scatter",
"bar",
Expand Down Expand Up @@ -457,6 +458,22 @@ def plot(
**kwargs
)

if kind == "step":
p = stepplot(
p,
source,
data_cols,
colormap,
hovertool,
xlabelname,
figure_options["x_axis_type"],
plot_data_points,
plot_data_points_size,
hovertool_string,
number_format,
**kwargs
)

if kind == "point":
p = pointplot(
p,
Expand Down Expand Up @@ -903,7 +920,8 @@ def plot(
return p


def lineplot(
def _base_lineplot(
linetype,
p,
source,
data_cols,
Expand All @@ -926,8 +944,9 @@ def lineplot(
marker = "circle"

# Add line (and optional scatter glyphs) to figure:
linetype = getattr(p, linetype.lower())
for name, color in zip(data_cols, colormap):
glyph = p.line(
glyph = linetype(
x="__x__values",
y=name,
legend=" " + name,
Expand Down Expand Up @@ -968,6 +987,68 @@ def lineplot(
return p


def lineplot(
p,
source,
data_cols,
colormap,
hovertool,
xlabelname,
x_axis_type,
plot_data_points,
plot_data_points_size,
hovertool_string,
number_format,
**kwargs
):
return _base_lineplot(
linetype="line",
p=p,
source=source,
data_cols=data_cols,
colormap=colormap,
hovertool=hovertool,
xlabelname=xlabelname,
x_axis_type=x_axis_type,
plot_data_points=plot_data_points,
plot_data_points_size=plot_data_points_size,
hovertool_string=hovertool_string,
number_format=number_format,
**kwargs
)


def stepplot(
p,
source,
data_cols,
colormap,
hovertool,
xlabelname,
x_axis_type,
plot_data_points,
plot_data_points_size,
hovertool_string,
number_format,
**kwargs
):
return _base_lineplot(
linetype="step",
p=p,
source=source,
data_cols=data_cols,
colormap=colormap,
hovertool=hovertool,
xlabelname=xlabelname,
x_axis_type=x_axis_type,
plot_data_points=plot_data_points,
plot_data_points_size=plot_data_points_size,
hovertool_string=hovertool_string,
number_format=number_format,
**kwargs
)


def pointplot(
p,
source,
Expand Down Expand Up @@ -1742,6 +1823,57 @@ def line(self, x=None, y=None, **kwargs):
"""
return self(kind="line", x=x, y=y, **kwargs)

def step(self, x=None, y=None, **kwargs):
"""
Plot DataFrame columns as step lines.

This function is useful to plot step lines using DataFrame's values
as coordinates.

Parameters
----------
x : int or str, optional
Columns to use for the horizontal axis.
Either the location or the label of the columns to be used.
By default, it will use the DataFrame indices.
y : int, str, or list of them, optional
The values to be plotted.
Either the location or the label of the columns to be used.
By default, it will use the remaining DataFrame numeric columns.
Copy link
Owner

Choose a reason for hiding this comment

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

maybe also add the mode keyword here, because this seems to be very specific and important for a stepplot.

**kwds
Keyword arguments to pass on to :meth:`pandas.DataFrame.plot_bokeh`.
Copy link
Owner

Choose a reason for hiding this comment

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

Keyword arguments to pass on to :meth:pandas.DataFrame.plot_bokeh and further to bokeh.plotting.figure.step


Returns
-------

Bokeh.plotting.figure or Bokeh.layouts.row

Examples
--------

.. plot::
:context: close-figs

The following example shows the populations for some animals
over the years.

>>> df = pd.DataFrame({
Copy link
Owner

Choose a reason for hiding this comment

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

Nice example

... 'pig': [20, 18, 489, 675, 1776],
... 'horse': [4, 25, 281, 600, 1900]
... }, index=[1990, 1997, 2003, 2009, 2014])
>>> steps = df.plot_bokeh.step()


.. plot::
:context: close-figs

The following example shows the relationship between both
populations.

>>> steps = df.plot_bokeh.step(x='pig', y='horse')
"""
return self(kind="step", x=x, y=y, **kwargs)

def point(self, x=None, y=None, **kwargs):
"""
Plot DataFrame columns as points.
Expand Down