Skip to content

Commit 23848ab

Browse files
author
Corey Ostrove
committed
Minor performance tweaks and clean up
1 parent c431fc3 commit 23848ab

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

pygsti/report/workspaceplots.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ def _nested_color_boxplot(plt_data_list_of_lists, colormap,
285285
plaquette_boundary_lines.append(dict(type="line", xref= 'paper', yref='y', x0=0, y0=y_bnd, x1=1, y1=y_bnd,
286286
line={'color':"#616263", 'width':1, 'dash':"solid"}))
287287

288-
for bnd_line in plaquette_boundary_lines:
289-
fig.plotlyfig.add_shape(bnd_line)
288+
fig.plotlyfig.update_layout(shapes=plaquette_boundary_lines)
290289
#Add grid lines between the squares within a plaquette
291290
#Can use a construction similar to the x/y boundary one to
292291
#get some reference points, but we need to include the endpoints here.
@@ -331,14 +330,10 @@ def _nested_color_boxplot(plt_data_list_of_lists, colormap,
331330
plaquette_grid_lines = []
332331
for y in y_pos_filtered:
333332
for endpoints in x_endpoints:
334-
#fig.plotlyfig.add_shape(type="line", x0=endpoints[0], y0=y, x1=endpoints[1], y1=y,
335-
# line={'color':"MediumPurple", 'width':.25, 'dash':"dot"})
336333
plaquette_grid_lines.append(dict(type="line", x0=endpoints[0], y0=y, x1=endpoints[1], y1=y,
337334
line={'color':"MediumPurple", 'width':.35, 'dash':"1px"}))
338335
for x in x_pos_filtered:
339336
for endpoints in y_endpoints:
340-
#fig.plotlyfig.add_shape(type="line", x0=x, y0=endpoints[0], x1=x, y1=endpoints[1],
341-
# line={'color':"MediumPurple", 'width':.25, 'dash':"dot"})
342337
plaquette_grid_lines.append(dict(type="line", x0=x, y0=endpoints[0], x1=x, y1=endpoints[1],
343338
line={'color':"MediumPurple", 'width':.35, 'dash':"1px"}))
344339

@@ -362,11 +357,18 @@ def _nested_color_boxplot(plt_data_list_of_lists, colormap,
362357
clicktoshow= 'onout', xclick=i, yclick=j,
363358
xshift= 20,
364359
visible= False, font = dict(size=12, family='monospace'),
365-
showarrow=False))
360+
showarrow=True))
361+
on_click_annotations.append(dict(x= i, y= j,
362+
yanchor= 'middle', xanchor= 'center',
363+
bordercolor= 'purple', borderwidth= 0,
364+
clicktoshow= 'onout',
365+
text='', #border pad value is a complete guess...
366+
visible= False, font = dict(size=12, family='monospace'),
367+
showarrow=True, arrowhead=3))
366368
#need to add these annotation to the layout here to have them properly work by default with the
367369
#button menu. (otherwise you need to toggle the button off and on again before they appear).
368370
fig.plotlyfig.update_layout(annotations = on_click_annotations)
369-
371+
370372
#create a pair of buttons for toggling on and off the inner grids:
371373
grid_button = dict(type="buttons",
372374
active=1,
@@ -668,22 +670,18 @@ def hover_label_fn(val, i, j, ii, jj):
668670

669671
#decide on some absolute distances (in pixels?) between the buttons and the bottom of the printable area.
670672
y_abs_0= 25
671-
y_abs_1= 65
673+
y_abs_1= 75
672674
#vertical plotting area should be (approximately at least) height - tmargin - bmargin
673675
plottable_height = height - tmargin - bmargin
674676
new_y_0 = -y_abs_0/plottable_height
675677
new_y_1 = -y_abs_1/plottable_height
676678
#Now let's update the updatemenus
677-
new_updatemenus = list(pfig.layout.updatemenus)
678-
#The first entry is the grid button, the second the hover button, and the third the clickable element button.
679-
#the last of these needs an additional vertical shift added.
680-
new_updatemenus[0].y = new_y_0
681-
new_updatemenus[1].y = new_y_0
682-
new_updatemenus[2].y = new_y_1
683-
684-
#now let's update the updatemenus in the figure.
685-
pfig.update_layout(updatemenus = new_updatemenus)
686-
679+
#updatemenus should be a tuple, but for some reason this looks like
680+
#it works...
681+
pfig['layout']['updatemenus'][0]['y'] = new_y_0
682+
pfig['layout']['updatemenus'][1]['y'] = new_y_0
683+
pfig['layout']['updatemenus'][2]['y'] = new_y_1
684+
687685
else: # fig is None => use a "No data to display" placeholder figure
688686
trace = go.Heatmap(z=_np.zeros((10, 10), 'd'),
689687
colorscale=[[0, 'white'], [1, 'black']],

0 commit comments

Comments
 (0)