Skip to content

Commit b329fb8

Browse files
committed
move endpts_to_intervals to utils from _scatterplot.py
1 parent e33ed1b commit b329fb8

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

plotly/figure_factory/_facet_grid.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,16 +550,17 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
550550
facet_row_labels=None, facet_col_labels=None,
551551
height=None, width=None, trace_type='scatter',
552552
scales='fixed', dtick_x=None, dtick_y=None,
553-
show_boxes=True, ggplot2=False, **kwargs):
553+
show_boxes=True, ggplot2=False, binsize=1, **kwargs):
554554
"""
555555
Returns figure for facet grid.
556556
557557
:param (pd.DataFrame) df: the dataframe of columns for the facet grid.
558-
:param (str) x: the key of the dataframe to be used as the x axis df.
559-
:param (str) y: the key of the dataframe to be used as the y axis df.
560-
:param (str) facet_row: the key for row filter column for the facet grid.
561-
:param (str) facet_col: the key for the column filter column for the facet
562-
grid.
558+
:param (str) x: the name of the dataframe column for the x axis data.
559+
:param (str) y: the name of the dataframe column for the y axis data.
560+
:param (str) facet_row: the name of the dataframe column that is used to
561+
facet the grid into row panels.
562+
:param (str) facet_col: the name of the dataframe column that is used to
563+
facet the grid into column panels.
563564
:param (str) color_name: the name of your dataframe column that will
564565
function as the colormap variable.
565566
:param (str|list|dict) colormap: the param that determines how the
@@ -593,6 +594,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
593594
:param (bool) ggplot2: draws the facet grid in the style of `ggplot2`. See
594595
http://ggplot2.tidyverse.org/reference/facet_grid.html for reference.
595596
Default = False
597+
:param (int) binsize: groups all data into bins of a given length.
596598
:param (dict) kwargs: a dictionary of scatterplot arguments.
597599
598600
Examples 1: One Way Faceting

plotly/figure_factory/_scatterplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def scatterplot_theme(dataframe, headers, diag, size, height, width, title,
552552

553553
else:
554554
if endpts:
555-
intervals = endpts_to_intervals(endpts)
555+
intervals = utils.endpts_to_intervals(endpts)
556556

557557
# Convert colormap to list of n RGB tuples
558558
if colormap_type == 'seq':

plotly/figure_factory/utils.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,50 @@ def validate_colorscale(colorscale):
441441

442442
validate_scale_values(scale_values)
443443
validate_colors(colorscale_colors)
444+
445+
446+
def endpts_to_intervals(endpts):
447+
"""
448+
Returns a list of intervals for categorical colormaps
449+
450+
Accepts a list or tuple of sequentially increasing numbers and returns
451+
a list representation of the mathematical intervals with these numbers
452+
as endpoints. For example, [1, 6] returns [[-inf, 1], [1, 6], [6, inf]]
453+
454+
:raises: (PlotlyError) If input is not a list or tuple
455+
:raises: (PlotlyError) If the input contains a string
456+
:raises: (PlotlyError) If any number does not increase after the
457+
previous one in the sequence
458+
"""
459+
length = len(endpts)
460+
# Check if endpts is a list or tuple
461+
if not (isinstance(endpts, (tuple)) or isinstance(endpts, (list))):
462+
raise exceptions.PlotlyError("The intervals_endpts argument must "
463+
"be a list or tuple of a sequence "
464+
"of increasing numbers.")
465+
# Check if endpts contains only numbers
466+
for item in endpts:
467+
if isinstance(item, str):
468+
raise exceptions.PlotlyError("The intervals_endpts argument "
469+
"must be a list or tuple of a "
470+
"sequence of increasing "
471+
"numbers.")
472+
# Check if numbers in endpts are increasing
473+
for k in range(length - 1):
474+
if endpts[k] >= endpts[k + 1]:
475+
raise exceptions.PlotlyError("The intervals_endpts argument "
476+
"must be a list or tuple of a "
477+
"sequence of increasing "
478+
"numbers.")
479+
else:
480+
intervals = []
481+
# add -inf to intervals
482+
intervals.append([float('-inf'), endpts[0]])
483+
for k in range(length - 1):
484+
interval = []
485+
interval.append(endpts[k])
486+
interval.append(endpts[k + 1])
487+
intervals.append(interval)
488+
# add +inf to intervals
489+
intervals.append([endpts[length - 1], float('inf')])
490+
return intervals

0 commit comments

Comments
 (0)