Skip to content

Commit 5896c21

Browse files
author
mahdis-z
committedJul 24, 2019
some changes to meet the checklist checkmarks
1 parent 5620d1d commit 5896c21

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed
 

‎python/parallel-categories-diagram.md

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ This example illustartes the hair color, eye color, and sex of a sample of 8 peo
7474

7575
```python
7676
import plotly.graph_objects as go
77-
parcats = go.Parcats(
77+
78+
fig = go.Figure(go.Parcats(
7879
dimensions=[
7980
{'label': 'Hair',
8081
'values': ['Black', 'Black', 'Black', 'Brown', 'Brown', 'Brown', 'Red', 'Brown']},
8182
{'label': 'Eye',
8283
'values': ['Brown', 'Brown', 'Brown', 'Brown', 'Brown', 'Blue', 'Blue', 'Blue']},
8384
{'label': 'Sex',
8485
'values': ['Female', 'Female', 'Female', 'Male', 'Female', 'Male', 'Male', 'Male']}]
85-
)
86+
))
8687

87-
fig = go.Figure(parcats)
8888
fig.show()
8989
```
9090

@@ -223,67 +223,39 @@ import numpy as np
223223
cars_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/imports-85.csv')
224224

225225
# Build parcats dimensions
226-
categorical_dimensions = [
227-
'body-style',
228-
'drive-wheels',
229-
'fuel-type'
230-
];
226+
categorical_dimensions = ['body-style', 'drive-wheels', 'fuel-type']
231227

232-
dimensions = [
233-
dict(values=cars_df[label], label=label)
234-
for label in categorical_dimensions
235-
]
228+
dimensions = [dict(values=cars_df[label], label=label) for label in categorical_dimensions]
236229

237230
# Build colorscale
238231
color = np.zeros(len(cars_df), dtype='uint8')
239232
colorscale = [[0, 'gray'], [0.33, 'gray'],
240233
[0.33, 'firebrick'], [0.66, 'firebrick'],
241-
[0.66, 'blue'], [1.0, 'blue']];
234+
[0.66, 'blue'], [1.0, 'blue']]
242235
cmin = -0.5
243236
cmax = 2.5
244237

245238
# Build figure as FigureWidget
246239
fig = go.FigureWidget(
247-
data=[
248-
go.Scatter(
249-
x=cars_df.horsepower,
250-
y=cars_df['highway-mpg'],
251-
marker={'color': color,
252-
'cmin': cmin,
253-
'cmax': cmax,
254-
'colorscale': colorscale,
255-
'showscale': True,
256-
'colorbar': {'tickvals': [0, 1, 2],
257-
'ticktext': ['None', 'Red', 'Blue']}
258-
},
259-
mode='markers'),
260-
261-
go.Parcats(
262-
domain={'y': [0, 0.4]},
263-
dimensions=dimensions,
264-
line={
265-
'colorscale': colorscale,
266-
'cmin': cmin,
267-
'cmax': cmax,
268-
'color': color,
269-
'shape': 'hspline'})
270-
],
271-
layout=go.Layout(
272-
height=800,
273-
xaxis={'title': 'Horsepower'},
274-
yaxis={'title': 'MPG',
275-
'domain': [0.6, 1]},
276-
dragmode='lasso',
277-
hovermode='closest')
240+
data=[go.Scatter(x=cars_df.horsepower, y=cars_df['highway-mpg'],
241+
marker={'color': color, 'cmin': cmin, 'cmax': cmax,
242+
'colorscale': colorscale, 'showscale': True,
243+
'colorbar': {'tickvals': [0, 1, 2], 'ticktext': ['None', 'Red', 'Blue']}},
244+
mode='markers'),
245+
246+
go.Parcats(domain={'y': [0, 0.4]}, dimensions=dimensions,
247+
line={'colorscale': colorscale, 'cmin': cmin,
248+
'cmax': cmax, 'color': color, 'shape': 'hspline'})]
278249
)
279250

251+
fig.update_layout(height=800, xaxis={'title': 'Horsepower'},
252+
yaxis={'title': 'MPG', 'domain': [0.6, 1]},
253+
dragmode='lasso', hovermode='closest')
254+
280255
# Build color selection widget
281256
color_toggle = widgets.ToggleButtons(
282257
options=['None', 'Red', 'Blue'],
283-
index=1,
284-
description='Brush Color:',
285-
disabled=False,
286-
)
258+
index=1, description='Brush Color:', disabled=False)
287259

288260
# Update color callback
289261
def update_color(trace, points, state):

0 commit comments

Comments
 (0)
Please sign in to comment.