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

Skip to content

Commit fdb1755

Browse files
committed
updated test with diag=box to test new change
1 parent ca9dd35 commit fdb1755

File tree

2 files changed

+122
-40
lines changed

2 files changed

+122
-40
lines changed

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,29 +1141,93 @@ def test_scatter_plot_matrix(self):
11411141
columns=['Numbers', 'Fruit'])
11421142

11431143
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
1144-
df=df, diag='scatter', height=1000, width=1000, size=13,
1144+
df=df, diag='box', height=1000, width=1000, size=13,
11451145
title='Scatterplot Matrix'
11461146
)
11471147

1148+
# exp_scatter_plot_matrix = {
1149+
# 'data': [{'marker': {'size': 13},
1150+
# 'mode': 'markers',
1151+
# 'showlegend': False,
1152+
# 'type': 'scatter',
1153+
# 'x': [2, 6, -15, 5, -2, 0],
1154+
# 'xaxis': 'x1',
1155+
# 'y': [2, 6, -15, 5, -2, 0],
1156+
# 'yaxis': 'y1'},
1157+
# {'marker': {'size': 13},
1158+
# 'mode': 'markers',
1159+
# 'showlegend': False,
1160+
# 'type': 'scatter',
1161+
# 'x': ['Apple',
1162+
# 'Pear',
1163+
# 'Apple',
1164+
# 'Pear',
1165+
# 'Apple',
1166+
# 'Apple'],
1167+
# 'xaxis': 'x2',
1168+
# 'y': [2, 6, -15, 5, -2, 0],
1169+
# 'yaxis': 'y2'},
1170+
# {'marker': {'size': 13},
1171+
# 'mode': 'markers',
1172+
# 'showlegend': False,
1173+
# 'type': 'scatter',
1174+
# 'x': [2, 6, -15, 5, -2, 0],
1175+
# 'xaxis': 'x3',
1176+
# 'y': ['Apple',
1177+
# 'Pear',
1178+
# 'Apple',
1179+
# 'Pear',
1180+
# 'Apple',
1181+
# 'Apple'],
1182+
# 'yaxis': 'y3'},
1183+
# {'marker': {'size': 13},
1184+
# 'mode': 'markers',
1185+
# 'showlegend': False,
1186+
# 'type': 'scatter',
1187+
# 'x': ['Apple',
1188+
# 'Pear',
1189+
# 'Apple',
1190+
# 'Pear',
1191+
# 'Apple',
1192+
# 'Apple'],
1193+
# 'xaxis': 'x4',
1194+
# 'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
1195+
# 'yaxis': 'y4'}],
1196+
# 'layout': {'height': 1000,
1197+
# 'showlegend': True,
1198+
# 'title': 'Scatterplot Matrix',
1199+
# 'width': 1000,
1200+
# 'xaxis1': {'anchor': 'y1',
1201+
# 'domain': [0.0, 0.45]},
1202+
# 'xaxis2': {'anchor': 'y2',
1203+
# 'domain': [0.55, 1.0]},
1204+
# 'xaxis3': {'anchor': 'y3',
1205+
# 'domain': [0.0, 0.45], 'title': 'Numbers'},
1206+
# 'xaxis4': {'anchor': 'y4',
1207+
# 'domain': [0.55, 1.0], 'title': 'Fruit'},
1208+
# 'yaxis1': {'anchor': 'x1',
1209+
# 'domain': [0.575, 1.0], 'title': 'Numbers'},
1210+
# 'yaxis2': {'anchor': 'x2',
1211+
# 'domain': [0.575, 1.0]},
1212+
# 'yaxis3': {'anchor': 'x3',
1213+
# 'domain': [0.0, 0.425], 'title': 'Fruit'},
1214+
# 'yaxis4': {'anchor': 'x4',
1215+
# 'domain': [0.0, 0.425]}}
1216+
# }
1217+
11481218
exp_scatter_plot_matrix = {
1149-
'data': [{'marker': {'size': 13},
1150-
'mode': 'markers',
1219+
'data': [{'name': None,
11511220
'showlegend': False,
1152-
'type': 'scatter',
1153-
'x': [2, 6, -15, 5, -2, 0],
1221+
'type': 'box',
11541222
'xaxis': 'x1',
11551223
'y': [2, 6, -15, 5, -2, 0],
11561224
'yaxis': 'y1'},
11571225
{'marker': {'size': 13},
11581226
'mode': 'markers',
11591227
'showlegend': False,
11601228
'type': 'scatter',
1161-
'x': ['Apple',
1162-
'Pear',
1163-
'Apple',
1164-
'Pear',
1165-
'Apple',
1166-
'Apple'],
1229+
'x': ['Apple', 'Pear', 'Apple',
1230+
'Pear', 'Apple', 'Apple'],
11671231
'xaxis': 'x2',
11681232
'y': [2, 6, -15, 5, -2, 0],
11691233
'yaxis': 'y2'},
@@ -1173,44 +1237,40 @@ def test_scatter_plot_matrix(self):
11731237
'type': 'scatter',
11741238
'x': [2, 6, -15, 5, -2, 0],
11751239
'xaxis': 'x3',
1176-
'y': ['Apple',
1177-
'Pear',
1178-
'Apple',
1179-
'Pear',
1180-
'Apple',
1181-
'Apple'],
1240+
'y': ['Apple', 'Pear', 'Apple',
1241+
'Pear', 'Apple', 'Apple'],
11821242
'yaxis': 'y3'},
1183-
{'marker': {'size': 13},
1184-
'mode': 'markers',
1243+
{'name': None,
11851244
'showlegend': False,
1186-
'type': 'scatter',
1187-
'x': ['Apple',
1188-
'Pear',
1189-
'Apple',
1190-
'Pear',
1191-
'Apple',
1192-
'Apple'],
1245+
'type': 'box',
11931246
'xaxis': 'x4',
1194-
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
1247+
'y': ['Apple', 'Pear', 'Apple',
1248+
'Pear', 'Apple', 'Apple'],
11951249
'yaxis': 'y4'}],
11961250
'layout': {'height': 1000,
11971251
'showlegend': True,
11981252
'title': 'Scatterplot Matrix',
11991253
'width': 1000,
12001254
'xaxis1': {'anchor': 'y1',
1201-
'domain': [0.0, 0.45]},
1255+
'domain': [0.0, 0.45],
1256+
'showticklabels': False},
12021257
'xaxis2': {'anchor': 'y2',
12031258
'domain': [0.55, 1.0]},
12041259
'xaxis3': {'anchor': 'y3',
1205-
'domain': [0.0, 0.45], 'title': 'Numbers'},
1260+
'domain': [0.0, 0.45],
1261+
'title': 'Numbers'},
12061262
'xaxis4': {'anchor': 'y4',
1207-
'domain': [0.55, 1.0], 'title': 'Fruit'},
1263+
'domain': [0.55, 1.0],
1264+
'showticklabels': False,
1265+
'title': 'Fruit'},
12081266
'yaxis1': {'anchor': 'x1',
1209-
'domain': [0.575, 1.0], 'title': 'Numbers'},
1267+
'domain': [0.575, 1.0],
1268+
'title': 'Numbers'},
12101269
'yaxis2': {'anchor': 'x2',
12111270
'domain': [0.575, 1.0]},
12121271
'yaxis3': {'anchor': 'x3',
1213-
'domain': [0.0, 0.425], 'title': 'Fruit'},
1272+
'domain': [0.0, 0.425],
1273+
'title': 'Fruit'},
12141274
'yaxis4': {'anchor': 'x4',
12151275
'domain': [0.0, 0.425]}}
12161276
}

plotly/tools.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,6 +3881,9 @@ def _scatterplot(dataframe, headers, diag, size,
38813881
title=title,
38823882
showlegend=True
38833883
)
3884+
3885+
fig = FigureFactory._hide_tick_labels_from_box_subplots(fig)
3886+
38843887
return fig
38853888

38863889
@staticmethod
@@ -4028,6 +4031,8 @@ def _scatterplot_dict(dataframe, headers, diag, size,
40284031
yaxis_key = 'yaxis{}'.format(1 + (dim * j))
40294032
fig['layout'][yaxis_key].update(title=headers[j])
40304033

4034+
fig = FigureFactory._hide_tick_labels_from_box_subplots(fig)
4035+
40314036
if diag == 'histogram':
40324037
fig['layout'].update(
40334038
height=height, width=width,
@@ -4036,13 +4041,6 @@ def _scatterplot_dict(dataframe, headers, diag, size,
40364041
barmode='stack')
40374042
return fig
40384043

4039-
elif diag == 'box':
4040-
fig['layout'].update(
4041-
height=height, width=width,
4042-
title=title,
4043-
showlegend=True)
4044-
return fig
4045-
40464044
else:
40474045
fig['layout'].update(
40484046
height=height, width=width,
@@ -4218,6 +4216,8 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
42184216
yaxis_key = 'yaxis{}'.format(1 + (dim * j))
42194217
fig['layout'][yaxis_key].update(title=headers[j])
42204218

4219+
fig = FigureFactory._hide_tick_labels_from_box_subplots(fig)
4220+
42214221
if diag == 'histogram':
42224222
fig['layout'].update(
42234223
height=height, width=width,
@@ -4391,6 +4391,8 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
43914391
yaxis_key = 'yaxis{}'.format(1 + (dim * j))
43924392
fig['layout'][yaxis_key].update(title=headers[j])
43934393

4394+
fig = FigureFactory._hide_tick_labels_from_box_subplots(fig)
4395+
43944396
if diag == 'histogram':
43954397
fig['layout'].update(
43964398
height=height, width=width,
@@ -4536,6 +4538,8 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
45364538
yaxis_key = 'yaxis{}'.format(1 + (dim * j))
45374539
fig['layout'][yaxis_key].update(title=headers[j])
45384540

4541+
fig = FigureFactory._hide_tick_labels_from_box_subplots(fig)
4542+
45394543
if diag == 'histogram':
45404544
fig['layout'].update(
45414545
height=height, width=width,
@@ -4558,6 +4562,23 @@ def _scatterplot_theme(dataframe, headers, diag, size, height,
45584562
showlegend=True)
45594563
return fig
45604564

4565+
@staticmethod
4566+
def _hide_tick_labels_from_box_subplots(fig):
4567+
"""
4568+
Hides tick labels for box plots in scatterplotmatrix subplots.
4569+
"""
4570+
boxplot_xaxes = []
4571+
for j, plot_data in enumerate(fig['data']):
4572+
if plot_data['type'] == 'box':
4573+
boxplot_xaxes.append(
4574+
'xaxis{}'.format(plot_data['xaxis'][-1])
4575+
)
4576+
4577+
for xaxis in boxplot_xaxes:
4578+
fig['layout'][xaxis]['showticklabels'] = False
4579+
4580+
return fig
4581+
45614582
@staticmethod
45624583
def _validate_index(index_vals):
45634584
"""
@@ -4806,7 +4827,8 @@ def create_scatterplotmatrix(df, index=None, endpts=None, diag='scatter',
48064827
that defines intervals on the real line. They are used to group
48074828
the entries in an index of numbers into their corresponding
48084829
interval and therefore can be treated as categorical data
4809-
:param (str) diag: sets the chart type for the main diagonal plots
4830+
:param (str) diag: sets the chart type for the main diagonal plots.
4831+
The options are 'scatter', 'histogram' and 'box'.
48104832
:param (int|float) height: sets the height of the chart
48114833
:param (int|float) width: sets the width of the chart
48124834
:param (float) size: sets the marker size (in px)

0 commit comments

Comments
 (0)