Skip to content

Commit

Permalink
Merge pull request #27 from gjeusel/add_step_plot
Browse files Browse the repository at this point in the history
Add step plot
  • Loading branch information
PatrikHlobil authored Jun 24, 2019
2 parents 66ab68d + 150871c commit ab3b4d2
Showing 1 changed file with 134 additions and 2 deletions.
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.
**kwds
Keyword arguments to pass on to :meth:`pandas.DataFrame.plot_bokeh`.
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({
... '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

0 comments on commit ab3b4d2

Please sign in to comment.