

# https://www.globalsino.com/ICs/
# Heatmap with input from a csv file

import pandas as pd
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots

df = pd.read_csv(r"C:\GlobalSino2\ICs\4279.csv", header=None)

print(df)

my_matrix = np.empty((5,5))
my_matrix[:] = np.nan

for i in range(1, (len(df))):
    y = int(df.values[i][1])
    x = int(df.values[i][0])
    Value = int(df.values[i][2])
    my_matrix[y,x] = Value
    my_matrix
    print(my_matrix)

fig = make_subplots()

fig.add_trace(go.Heatmap(z=np.where(my_matrix!=1, np.nan, my_matrix),colorscale = [[0, 'blue'], [1, 'blue']], hoverinfo='skip'))
fig.add_trace(go.Heatmap(z=np.where(my_matrix!=2, np.nan, my_matrix),colorscale = [[0, 'yellow'], [1, 'yellow']], hoverinfo='skip'))
fig.add_trace(go.Heatmap(z=np.where(my_matrix!=3, np.nan, my_matrix),colorscale = [[0, 'red'], [1, 'red']], hoverinfo='skip'))

fig.add_trace(go.Heatmap(z=my_matrix,colorscale = [[0, 'blue'], [1, 'blue']],opacity=0))

fig.update_traces(showscale=False)

button_1 = dict(
    method='restyle',
    label="Blue",
    visible=True,
    args=[{'visible':True}, [0]],
    args2 = [{'visible': False}, [0]],
)

button_2 = dict(
    method='restyle',
    label="Yellow",
    visible=True,
    args=[{'visible':True}, [1]],
    args2 = [{'visible': False}, [1]],
)

button_3 = dict(
    method='restyle',
    label="Red",
    visible=True,
    args=[{'visible':True}, [2]],
    args2 = [{'visible': False}, [2]],
)

button_4 = dict(
    method='restyle',
    label="All",
    visible=True,
    args=[{'visible':True}],
    args2 = [{'visible': False}],
)

fig.update_layout(width=600, height=600,
    updatemenus=[
        dict(
            type = "buttons",
            direction = "left",
            buttons=[button_1,button_2, button_3, button_4],
            pad={"b": 5, "t": 5},
            showactive=False,
            x=.1,
            xanchor="left",
            y=1.1,
            yanchor="top",
            bgcolor = '#AAAAAA',
            bordercolor = '#FFFFFF',
            font=dict(color=("blue"))
        ),
    ]
)
# fig.show()
fig.write_html(r"C:\GlobalSino2\ICs\4279.html")
