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

Skip to content

Commit e25d392

Browse files
committed
Add a test for scatterplotmatrix with index
1 parent f4764b4 commit e25d392

File tree

1 file changed

+114
-43
lines changed

1 file changed

+114
-43
lines changed

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 114 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -761,49 +761,72 @@ def test_scatter_plot_matrix(self):
761761

762762
exp_scatter_plot_matrix = {
763763
'data': [{'marker': {'size': 13},
764-
'mode': 'markers',
765-
'showlegend': False,
766-
'type': 'scatter',
767-
'x': [2, 6, -15, 5, -2, 0],
768-
'xaxis': 'x1',
769-
'y': [2, 6, -15, 5, -2, 0],
770-
'yaxis': 'y1'},
771-
{'marker': {'size': 13},
772-
'mode': 'markers',
773-
'showlegend': False,
774-
'type': 'scatter',
775-
'x': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
776-
'xaxis': 'x2',
777-
'y': [2, 6, -15, 5, -2, 0],
778-
'yaxis': 'y2'},
779-
{'marker': {'size': 13},
780-
'mode': 'markers',
781-
'showlegend': False,
782-
'type': 'scatter',
783-
'x': [2, 6, -15, 5, -2, 0],
784-
'xaxis': 'x3',
785-
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
786-
'yaxis': 'y3'},
787-
{'marker': {'size': 13},
788-
'mode': 'markers',
789-
'showlegend': False,
790-
'type': 'scatter',
791-
'x': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
792-
'xaxis': 'x4',
793-
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
794-
'yaxis': 'y4'}],
795-
'layout': {'height': 1000,
796-
'showlegend': True,
797-
'title': 'Scatterplot Matrix',
798-
'width': 1000,
799-
'xaxis1': {'anchor': 'y1', 'domain': [0.0, 0.45]},
800-
'xaxis2': {'anchor': 'y2', 'domain': [0.55, 1.0]},
801-
'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.45], 'title': 'Numbers'},
802-
'xaxis4': {'anchor': 'y4', 'domain': [0.55, 1.0], 'title': 'Fruit'},
803-
'yaxis1': {'anchor': 'x1', 'domain': [0.575, 1.0], 'title': 'Numbers'},
804-
'yaxis2': {'anchor': 'x2', 'domain': [0.575, 1.0]},
805-
'yaxis3': {'anchor': 'x3', 'domain': [0.0, 0.425], 'title': 'Fruit'},
806-
'yaxis4': {'anchor': 'x4', 'domain': [0.0, 0.425]}}
764+
'mode': 'markers',
765+
'showlegend': False,
766+
'type': 'scatter',
767+
'x': [2, 6, -15, 5, -2, 0],
768+
'xaxis': 'x1',
769+
'y': [2, 6, -15, 5, -2, 0],
770+
'yaxis': 'y1'},
771+
{'marker': {'size': 13},
772+
'mode': 'markers',
773+
'showlegend': False,
774+
'type': 'scatter',
775+
'x': ['Apple',
776+
'Pear',
777+
'Apple',
778+
'Pear',
779+
'Apple',
780+
'Apple'],
781+
'xaxis': 'x2',
782+
'y': [2, 6, -15, 5, -2, 0],
783+
'yaxis': 'y2'},
784+
{'marker': {'size': 13},
785+
'mode': 'markers',
786+
'showlegend': False,
787+
'type': 'scatter',
788+
'x': [2, 6, -15, 5, -2, 0],
789+
'xaxis': 'x3',
790+
'y': ['Apple',
791+
'Pear',
792+
'Apple',
793+
'Pear',
794+
'Apple',
795+
'Apple'],
796+
'yaxis': 'y3'},
797+
{'marker': {'size': 13},
798+
'mode': 'markers',
799+
'showlegend': False,
800+
'type': 'scatter',
801+
'x': ['Apple',
802+
'Pear',
803+
'Apple',
804+
'Pear',
805+
'Apple',
806+
'Apple'],
807+
'xaxis': 'x4',
808+
'y': ['Apple', 'Pear', 'Apple', 'Pear', 'Apple', 'Apple'],
809+
'yaxis': 'y4'}],
810+
'layout': {'height': 1000,
811+
'showlegend': True,
812+
'title': 'Scatterplot Matrix',
813+
'width': 1000,
814+
'xaxis1': {'anchor': 'y1',
815+
'domain': [0.0, 0.45]},
816+
'xaxis2': {'anchor': 'y2',
817+
'domain': [0.55, 1.0]},
818+
'xaxis3': {'anchor': 'y3',
819+
'domain': [0.0, 0.45], 'title': 'Numbers'},
820+
'xaxis4': {'anchor': 'y4',
821+
'domain': [0.55, 1.0], 'title': 'Fruit'},
822+
'yaxis1': {'anchor': 'x1',
823+
'domain': [0.575, 1.0], 'title': 'Numbers'},
824+
'yaxis2': {'anchor': 'x2',
825+
'domain': [0.575, 1.0]},
826+
'yaxis3': {'anchor': 'x3',
827+
'domain': [0.0, 0.425], 'title': 'Fruit'},
828+
'yaxis4': {'anchor': 'x4',
829+
'domain': [0.0, 0.425]}}
807830
}
808831

809832
self.assert_dict_equal(test_scatter_plot_matrix['data'][0],
@@ -814,3 +837,51 @@ def test_scatter_plot_matrix(self):
814837

815838
self.assert_dict_equal(test_scatter_plot_matrix['layout'],
816839
exp_scatter_plot_matrix['layout'])
840+
841+
def test_scatter_plot_matrix_with_index(self):
842+
843+
# check if test scatter plot matrix with index matches
844+
# the expected output
845+
df = pd.DataFrame([[2, 'Apple'], [6, 'Pear'],
846+
[-15, 'Apple'], [5, 'Pear'],
847+
[-2, 'Apple'], [0, 'Apple']],
848+
columns=['Numbers', 'Fruit'])
849+
850+
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
851+
df, diag='scatter', index='Fruit', height=1000, width=1000,
852+
size=13, title='Scatterplot Matrix', use_theme=False
853+
)
854+
855+
exp_scatter_plot_matrix = {'data': [{'marker': {'color': 'rgb(31, 119, 180)', 'size': 13},
856+
'mode': 'markers',
857+
'name': 'Pear',
858+
'showlegend': False,
859+
'type': 'scatter',
860+
'x': [6, 5],
861+
'xaxis': 'x1',
862+
'y': [6, 5],
863+
'yaxis': 'y1'},
864+
{'marker': {'color': 'rgb(255, 127, 14)', 'size': 13},
865+
'mode': 'markers',
866+
'name': 'Apple',
867+
'showlegend': False,
868+
'type': 'scatter',
869+
'x': [2, -15, -2, 0],
870+
'xaxis': 'x1',
871+
'y': [2, -15, -2, 0],
872+
'yaxis': 'y1'}],
873+
'layout': {'height': 1000,
874+
'showlegend': True,
875+
'title': 'Scatterplot Matrix',
876+
'width': 1000,
877+
'xaxis1': {'anchor': 'y1', 'domain': [0.0, 1.0], 'title': 'Numbers'},
878+
'yaxis1': {'anchor': 'x1', 'domain': [0.0, 1.0], 'title': 'Numbers'}}}
879+
880+
self.assert_dict_equal(test_scatter_plot_matrix['data'][0],
881+
exp_scatter_plot_matrix['data'][0])
882+
883+
self.assert_dict_equal(test_scatter_plot_matrix['data'][1],
884+
exp_scatter_plot_matrix['data'][1])
885+
886+
self.assert_dict_equal(test_scatter_plot_matrix['layout'],
887+
exp_scatter_plot_matrix['layout'])

0 commit comments

Comments
 (0)