-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add step plot #27
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,7 @@ def plot( | |
# Check plot kind input: | ||
allowed_kinds = [ | ||
"line", | ||
"step", | ||
"point", | ||
"scatter", | ||
"bar", | ||
|
@@ -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, | ||
|
@@ -903,7 +920,8 @@ def plot( | |
return p | ||
|
||
|
||
def lineplot( | ||
def _base_lineplot( | ||
linetype, | ||
p, | ||
source, | ||
data_cols, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keyword arguments to pass on to :meth: |
||
|
||
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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.