Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7cf7ac8

Browse files
committed
webgl in scaterplotmatrix
1 parent 8fdd412 commit 7cf7ac8

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

plotly/tools.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,7 +3805,7 @@ def dist_origin(x, y, z):
38053805
return graph_objs.Figure(data=data1, layout=layout)
38063806

38073807
@staticmethod
3808-
def _scatterplot(dataframe, headers, diag, size,
3808+
def _scatterplot(dataframe, headers, diag, size, webgl,
38093809
height, width, title, **kwargs):
38103810
"""
38113811
Refer to FigureFactory.create_scatterplotmatrix() for docstring
@@ -3879,10 +3879,13 @@ def _scatterplot(dataframe, headers, diag, size,
38793879

38803880
FigureFactory._hide_tick_labels_from_box_subplots(fig)
38813881

3882+
if webgl is True:
3883+
FigureFactory._change_figure_to_webgl(fig)
3884+
38823885
return fig
38833886

38843887
@staticmethod
3885-
def _scatterplot_dict(dataframe, headers, diag, size,
3888+
def _scatterplot_dict(dataframe, headers, diag, size, webgl,
38863889
height, width, title, index, index_vals,
38873890
endpts, colormap, colormap_type, **kwargs):
38883891
"""
@@ -4028,6 +4031,9 @@ def _scatterplot_dict(dataframe, headers, diag, size,
40284031

40294032
FigureFactory._hide_tick_labels_from_box_subplots(fig)
40304033

4034+
if webgl is True:
4035+
FigureFactory._change_figure_to_webgl(fig)
4036+
40314037
if diag == 'histogram':
40324038
fig['layout'].update(
40334039
height=height, width=width,
@@ -4044,7 +4050,7 @@ def _scatterplot_dict(dataframe, headers, diag, size,
40444050
return fig
40454051

40464052
@staticmethod
4047-
def _scatterplot_theme(dataframe, headers, diag, size, height,
4053+
def _scatterplot_theme(dataframe, headers, diag, size, webgl, height,
40484054
width, title, index, index_vals, endpts,
40494055
colormap, colormap_type, **kwargs):
40504056
"""
@@ -4213,6 +4219,9 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
42134219

42144220
FigureFactory._hide_tick_labels_from_box_subplots(fig)
42154221

4222+
if webgl is True:
4223+
FigureFactory._change_figure_to_webgl(fig)
4224+
42164225
if diag == 'histogram':
42174226
fig['layout'].update(
42184227
height=height, width=width,
@@ -4388,6 +4397,9 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
43884397

43894398
FigureFactory._hide_tick_labels_from_box_subplots(fig)
43904399

4400+
if webgl is True:
4401+
FigureFactory._change_figure_to_webgl(fig)
4402+
43914403
if diag == 'histogram':
43924404
fig['layout'].update(
43934405
height=height, width=width,
@@ -4535,6 +4547,9 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
45354547

45364548
FigureFactory._hide_tick_labels_from_box_subplots(fig)
45374549

4550+
if webgl is True:
4551+
FigureFactory._change_figure_to_webgl(fig)
4552+
45384553
if diag == 'histogram':
45394554
fig['layout'].update(
45404555
height=height, width=width,
@@ -4558,10 +4573,20 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
45584573
return fig
45594574

45604575
@staticmethod
4561-
def _hide_tick_labels_from_box_subplots(fig):
4576+
def _change_figure_to_webgl(fig):
45624577
"""
4563-
Hides tick labels for box plots in scatterplotmatrix subplots.
4578+
Changes all scatter traces in figure to 'scattergl' type.
4579+
4580+
Only works if all traces are of type 'scatter'.
45644581
"""
4582+
if all(trace['type'] == 'scatter' for trace in fig['data']):
4583+
for trace in fig['data']:
4584+
if trace['type'] == 'scatter':
4585+
trace['type'] = 'scattergl'
4586+
4587+
@staticmethod
4588+
def _hide_tick_labels_from_box_subplots(fig):
4589+
"""Hides tick labels for box plots in scatterplotmatrix subplots."""
45654590
boxplot_xaxes = []
45664591
for trace in fig['data']:
45674592
if trace['type'] == 'box':
@@ -4808,24 +4833,25 @@ def _unlabel_rgb(colors):
48084833

48094834
@staticmethod
48104835
def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
4811-
height=500, width=500, size=6,
4836+
height=500, width=500, size=6, webgl=False,
48124837
title='Scatterplot Matrix', colormap=None,
48134838
colormap_type='cat', dataframe=None,
48144839
headers=None, index_vals=None, **kwargs):
48154840
"""
48164841
Returns data for a scatterplot matrix.
48174842
4818-
:param (array) df: array of the data with column headers
4819-
:param (str) index: name of the index column in data array
4843+
:param (array) df: array of the data with column headers.
4844+
:param (str) index: name of the index column in data array.
48204845
:param (list|tuple) endpts: takes an increasing sequece of numbers
48214846
that defines intervals on the real line. They are used to group
48224847
the entries in an index of numbers into their corresponding
4823-
interval and therefore can be treated as categorical data
4848+
interval and therefore can be treated as categorical data.
48244849
:param (str) diag: sets the chart type for the main diagonal plots.
48254850
The options are 'scatter', 'histogram' and 'box'.
4826-
:param (int|float) height: sets the height of the chart
4827-
:param (int|float) width: sets the width of the chart
4828-
:param (float) size: sets the marker size (in px)
4851+
:param (int|float) height: sets the height of the chart.
4852+
:param (int|float) width: sets the width of the chart.
4853+
:param (float) size: sets the marker size (in px).
4854+
:param (bool) webgl: if True, plots all scatterplots with WebGL.
48294855
:param (str) title: the title label of the scatterplot matrix
48304856
:param (str|tuple|list|dict) colormap: either a plotly scale name,
48314857
an rgb or hex color, a color tuple, a list of colors or a
@@ -4836,7 +4862,7 @@ def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
48364862
members.
48374863
If colormap is a dictionary, all the string entries in
48384864
the index column must be a key in colormap. In this case, the
4839-
colormap_type is forced to 'cat' or categorical
4865+
colormap_type is forced to 'cat' or categorical.
48404866
:param (str) colormap_type: determines how colormap is interpreted.
48414867
Valid choices are 'seq' (sequential) and 'cat' (categorical). If
48424868
'seq' is selected, only the first two colors in colormap will be
@@ -4845,10 +4871,10 @@ def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
48454871
forced if all index values are numeric.
48464872
If 'cat' is selected, a color from colormap will be assigned to
48474873
each category from index, including the intervals if endpts is
4848-
being used
4874+
being used.
48494875
:param (dict) **kwargs: a dictionary of scatterplot arguments
48504876
The only forbidden parameters are 'size', 'color' and
4851-
'colorscale' in 'marker'
4877+
'colorscale' in 'marker'.
48524878
48534879
Example 1: Vanilla Scatterplot Matrix
48544880
```
@@ -5035,8 +5061,8 @@ def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
50355061
# Check for same data-type in df columns
50365062
FigureFactory._validate_dataframe(dataframe)
50375063
figure = FigureFactory._scatterplot(dataframe, headers, diag,
5038-
size, height, width, title,
5039-
**kwargs)
5064+
size, webgl, height, width,
5065+
title, **kwargs)
50405066
return figure
50415067
else:
50425068
# Validate index selection
@@ -5066,16 +5092,16 @@ def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
50665092
"names in the index "
50675093
"must be keys.")
50685094
figure = FigureFactory._scatterplot_dict(
5069-
dataframe, headers, diag, size, height, width, title,
5070-
index, index_vals, endpts, colormap, colormap_type,
5095+
dataframe, headers, diag, size, webgl, height, width,
5096+
title, index, index_vals, endpts, colormap, colormap_type,
50715097
**kwargs
50725098
)
50735099
return figure
50745100

50755101
else:
50765102
figure = FigureFactory._scatterplot_theme(
5077-
dataframe, headers, diag, size, height, width, title,
5078-
index, index_vals, endpts, colormap, colormap_type,
5103+
dataframe, headers, diag, size, webgl, height, width,
5104+
title, index, index_vals, endpts, colormap, colormap_type,
50795105
**kwargs
50805106
)
50815107
return figure

0 commit comments

Comments
 (0)