Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebff53e

Browse filesBrowse files
committed
Added more tests and fixed axis reference
1 parent 16c74c1 commit ebff53e
Copy full SHA for ebff53e

File tree

Expand file treeCollapse file tree

2 files changed

+76
-31
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+76
-31
lines changed

‎plotly/tests/test_optional/test_opt_tracefactory.py

Copy file name to clipboardExpand all lines: plotly/tests/test_optional/test_opt_tracefactory.py
+62-29Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,71 @@ def test_default_dendrogram(self):
113113
[1, 1, 3, 4],
114114
[1, 2, 1, 4],
115115
[1, 2, 3, 1]]))
116-
expected_dendro_data = [{'marker': {'color': 'rgb(255,133,27)'},
117-
'mode': 'lines', 'xaxis': 'xs',
118-
'yaxis': 'y',
119-
'y': np.array([0., 1., 1., 0.]),
120-
'x': np.array([25., 25., 35., 35.]),
121-
'type': u'scatter'},
122-
{'marker': {'color': 'rgb(255,133,27)'},
123-
'mode': 'lines',
124-
'xaxis': 'x',
125-
'yaxis': 'y',
126-
'y': np.array([0., 2.23606798,
127-
2.23606798, 1.]),
128-
'x': np.array([15., 15., 30., 30.]),
129-
'type': u'scatter'},
130-
{'marker': {'color': 'blue'},
131-
'mode': 'lines',
132-
'xaxis': 'x',
133-
'yaxis': 'y',
134-
'y': np.array([0., 3.60555128,
135-
3.60555128, 2.23606798]),
136-
'x': np.array([5., 5., 22.5, 22.5]),
137-
'type': u'scatter'}]
138-
139-
self.assertEqual(len(dendro['data']), len(expected_dendro_data))
140-
self.assertTrue(np.array_equal(dendro['layout']['x']['ticktext'],
141-
np.array(['3', '2', '0', '1'])))
142-
116+
expected_data = [{'marker': {'color': 'rgb(255,133,27)'},
117+
'mode': 'lines', 'xaxis': 'xs',
118+
'yaxis': 'y',
119+
'y': np.array([0., 1., 1., 0.]),
120+
'x': np.array([25., 25., 35., 35.]),
121+
'type': u'scatter'},
122+
{'marker': {'color': 'rgb(255,133,27)'},
123+
'mode': 'lines',
124+
'xaxis': 'x',
125+
'yaxis': 'y',
126+
'y': np.array([0., 2.23606798,
127+
2.23606798, 1.]),
128+
'x': np.array([15., 15., 30., 30.]),
129+
'type': u'scatter'},
130+
{'marker': {'color': 'blue'},
131+
'mode': 'lines',
132+
'xaxis': 'x',
133+
'yaxis': 'y',
134+
'y': np.array([0., 3.60555128,
135+
3.60555128, 2.23606798]),
136+
'x': np.array([5., 5., 22.5, 22.5]),
137+
'type': u'scatter'}]
138+
expected_layout = {'width': '100%',
139+
'showlegend': False,
140+
'autoscale': False,
141+
'x': {'showticklabels': True,
142+
'tickmode': 'array',
143+
'ticks': 'outside',
144+
'showgrid': False,
145+
'mirror': 'allticks',
146+
'zeroline': False,
147+
'showline': True,
148+
'ticktext': np.array(['3', '2',
149+
'0', '1'],
150+
dtype='|S1'),
151+
'rangemode': 'tozero',
152+
'type': 'linear',
153+
'tickvals': np.array([5.0, 15.0,
154+
25.0, 35.0])},
155+
'y': {'showticklabels': True,
156+
'ticks': 'outside',
157+
'showgrid': False,
158+
'mirror': 'allticks',
159+
'zeroline': False,
160+
'showline': True,
161+
'rangemode': 'tozero',
162+
'type': 'linear'},
163+
'hovermode': 'closest'}
164+
165+
# Make sure data is as expected
166+
self.assertEqual(len(dendro['data']), len(expected_data))
143167
for i in range(1, len(dendro['data'])):
144168
self.assertTrue(np.allclose(dendro['data'][i]['x'],
145-
expected_dendro_data[i]['x']))
169+
expected_data[i]['x']))
146170
self.assertTrue(np.allclose(dendro['data'][i]['y'],
147-
expected_dendro_data[i]['y']))
171+
expected_data[i]['y']))
172+
173+
# Make sure layout is as expected
174+
self.assertTrue(np.array_equal(dendro['layout']['x']['ticktext'],
175+
expected_layout['x']['ticktext']))
176+
self.assertTrue(np.array_equal(dendro['layout']['x']['tickvals'],
177+
expected_layout['x']['tickvals']))
178+
self.assertEqual(dendro['layout']['x']['ticks'], 'outside')
179+
self.assertEqual(dendro['layout']['y']['ticks'], 'outside')
180+
self.assertEqual(dendro['layout']['width'], expected_layout['width'])
148181

149182
def test_dendrogram_random_matrix(self):
150183
# create a random uncorrelated matrix

‎plotly/tools.py

Copy file name to clipboardExpand all lines: plotly/tools.py
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,8 +3124,20 @@ def get_dendrogram_traces(self, X, colorscale):
31243124
y=np.multiply(self.sign[self.yaxis], ys),
31253125
mode='lines',
31263126
marker=Marker(color=colors[color_key]))
3127-
trace['xaxis'] = self.xaxis
3128-
trace['yaxis'] = self.yaxis
3127+
3128+
try:
3129+
x_index = int(self.xaxis[-1])
3130+
except ValueError:
3131+
x_index = ''
3132+
3133+
try:
3134+
y_index = int(self.yaxis[-1])
3135+
except ValueError:
3136+
y_index = ''
3137+
3138+
trace['xaxis'] = 'x' + x_index
3139+
trace['yaxis'] = 'y' + y_index
3140+
31293141
trace_list.append(trace)
31303142

31313143
return trace_list, icoord, dcoord, ordered_labels, P['leaves']

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.