Hello,
I want to plot trace1 on trace0 that is a Heatmap of a picture. I have a dropdown button to select different trace1 data. When I run this code, the 2 traces are perfect, but when I use the dropdown button, the trace0 is affected… It’s weird that we can see something on the left…
Thank you for you help !
os.chdir(FolderPath)
init_file = glob.glob('*INIT.json')
init_noz_check_image = glob.glob('*INIT.png')
# Init NozCheck
with open(FolderPath + "/" + init_file[0], 'r') as json_file:
init_dict = json.load(json_file)
nozzles_xy = np.array(init_dict["Nozzles XY-Coordinates"])
# Detected Nozzles
detected_noz_tab = np.zeros((NbreMeasure, 1280, 2))
for i in range(NbreMeasure):
with open(FolderPath + "/" + files[FirstToSee + i], 'r') as json_file:
recreated_dict = json.load(json_file)
boolean_vector = np.array(recreated_dict["Nozzle Vector"], dtype=bool)
detected_noz_test = nozzles_xy[boolean_vector, :]
# Array that contains Detected Nozzles of All selected JSON
detected_noz_tab[i, 0:len(detected_noz_test), :] = detected_noz_test
# Image
img = cv2.imread(FolderPath + "/" + init_noz_check_image[0], cv2.IMREAD_GRAYSCALE)
# Create the detected Nozzles trace
trace1 = go.Scatter(x=detected_noz_tab[0, :, 0], y=detected_noz_tab[0, :, 1], mode='markers', name='trace1',
marker=dict(size=7, color='red'))
# Create img trace for image background
trace0 = go.Heatmap(z=img, showscale=False, colorscale='gray', name='trace0')
data = [trace0, trace1]
options = []
for i in range(NbreMeasure):
options.append(dict(label=f'Measure {i}',
method='update',
args=[{'x': [detected_noz_tab[i, :, 0]]},
{'y': [detected_noz_tab[i, :, 1]]},
]))
layout = dict(title='aaa',
xaxis=dict(title="aaaa"),
yaxis=dict(title="bbb"),
hovermode='closest',
updatemenus=[dict(
type='dropdown',
buttons=options,
direction='down',
showactive=True,
x=0.1,
xanchor='left',
y=1.1,
yanchor='top'
)])
fig = dict(data=data, layout=layout)
plot_url = plotly.offline.plot(fig, filename='scatter.html')