what do you mean? would you rather have incomplete code? oh im sorry i use dash. my question with plotly still stood. there is plotly in that code.
Yes you were correct about the division thankyou.
the solution was zip(((dt.datetime.fromisoformat(x), float(y)/100) for x, y, *_ in plots))
)
import dash
from dash.dependencies import Output, Input, State
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
import csv
import itertools
import datetime as dt
import attr
import copy
@attr.s(frozen=True)
class Plot:
xs = attr.ib()
ys = attr.ib()
def _humidity():
with open("z:/Humidity Log.txt", "r") as csvfile:
reader = csv.reader(csvfile)
plots = itertools.islice(reader, None, None, 1)
return Plot(
*zip(*((dt.datetime.fromisoformat(x), float(y)/100) for x, y, *_ in plots))
)
def _temp():
with open("Z:/Temp Log.txt", "r") as csvfile:
reader = csv.reader(csvfile)
plots = itertools.islice(reader, None, None, 1)
return Plot(
*zip(*((dt.datetime.fromisoformat(x), float(y)) for x, y, *_ in plots))
)
def _auxInput():
with open("Z:/Temp Log.txt", "r") as csvfile:
reader = csv.reader(csvfile)
plots = itertools.islice(reader, None, None, 1)
return Plot(
*zip(*((dt.datetime.fromisoformat(x), float(y)) for x, y, *_ in plots))
)
def auxinput(n):
aux = _auxInput()
return {
"data": [
plotly.graph_objs.Scatter(
x=list(aux.xs),
y=list(aux.ys),
line={"color": "#008f13"},
name="A/C Run-time",
mode="lines+markers",
),
],
"layout": go.Layout(
uirevision="null",
height=500,
plot_bgcolor="rgb(219, 219, 219)",
xaxis={"type": "date", "range": [min(aux.xs), max(aux.xs)],},
yaxis_tickwidth=2,
xaxis_tickangle=45,
yaxis_linewidth=1,
xaxis_linewidth=1,
xaxis_tickformatstops=[
dict(dtickrange=[None, 1000], value="%H:%M:%S.%L ms"),
dict(dtickrange=[1000, 60000], value="%H:%M:%S s"),
dict(dtickrange=[60000, 3600000], value="%H:%M m"),
dict(dtickrange=[3600000, 86400000], value="%H:%M h"),
dict(dtickrange=[86400000, 604800000], value="%e. %b d"),
dict(dtickrange=[604800000, "M1"], value="%e. %b w"),
dict(dtickrange=["M1", "M12"], value="%b '%y M"),
dict(dtickrange=["M12", None], value="%Y Y"),
],
yaxis={
"title": "A/C Run-time",
"fixedrange": True,
"autorange": True,
"range": [min(aux.ys), max(aux.ys)],
},
),
}
def temperature(n):
temp = _temp()
return {
"data": [
plotly.graph_objs.Scatter(
x=list(temp.xs),
y=list(temp.ys),
line={"color": "#f51000"},
name="Temperature",
mode="lines+markers",
),
],
"layout": go.Layout(
uirevision="any",
height=500,
plot_bgcolor="rgb(219, 219, 219)",
xaxis={"type": "date", "range": [min(temp.xs), max(temp.xs)],},
yaxis_tickwidth=2,
xaxis_tickangle=45,
yaxis_linewidth=1,
xaxis_linewidth=1,
xaxis_tickformatstops=[
dict(dtickrange=[None, 1000], value="%H:%M:%S.%L ms"),
dict(dtickrange=[1000, 60000], value="%H:%M:%S s"),
dict(dtickrange=[60000, 3600000], value="%H:%M m"),
dict(dtickrange=[3600000, 86400000], value="%H:%M h"),
dict(dtickrange=[86400000, 604800000], value="%e. %b d"),
dict(dtickrange=[604800000, "M1"], value="%e. %b w"),
dict(dtickrange=["M1", "M12"], value="%b '%y M"),
dict(dtickrange=["M12", None], value="%Y Y"),
],
yaxis={
"title": "Temperature",
"fixedrange": True,
"autorange": True,
"range": [min(temp.ys), max(temp.ys)],
},
),
}
def humidity(n):
humidity = _humidity()
return {
"data": [
plotly.graph_objs.Scatter(
x=list(humidity.xs),
y=list(humidity.ys),
line={"color": "#0539f7"},
name="Humidity",
mode="lines+markers",
),
],
"layout": go.Layout(
uirevision="null",
height=500,
plot_bgcolor="rgb(219, 219, 219)",
yaxis_tickwidth=2,
#yaxis_tickmode='%',
yaxis_tickformat='%',
xaxis_tickangle=45,
yaxis_linewidth=1,
xaxis_linewidth=1,
xaxis_tickformatstops=[
dict(dtickrange=[None, 1000], value="%H:%M:%S.%L ms"),
dict(dtickrange=[1000, 60000], value="%H:%M:%S s"),
dict(dtickrange=[60000, 3600000], value="%H:%M m"),
dict(dtickrange=[3600000, 86400000], value="%H:%M h"),
dict(dtickrange=[86400000, 604800000], value="%e. %b d"),
dict(dtickrange=[604800000, "M1"], value="%e. %b w"),
dict(dtickrange=["M1", "M12"], value="%b '%y M"),
dict(dtickrange=["M12", None], value="%Y Y"),
],
xaxis={"type": "date", "range": [min(humidity.xs), max(humidity.xs)],},
yaxis={
"title": "Humidity",
"fixedrange": True,
"range": [min(humidity.ys), max(humidity.ys)],
},
),
}
app = dash.Dash(__name__)
app.title = "Temp/Humidity Graph"
app.layout = html.Div(
[
dcc.RadioItems(
id="lock-zoom",
options=[{"label": i, "value": i} for i in ["Lock View", "Refresh View"]],
value="Lock View",
),
dcc.Graph(
id="live-temperature",
animate=False,
config={
"displaylogo": False,
"scrollZoom": True,
"modeBarButtonsToRemove": ["lasso2d", "toggleSpikelines"],
},
figure=temperature(0),
),
dcc.Graph(
id="live-humidity",
animate=False,
config={
"displaylogo": False,
"scrollZoom": True,
"modeBarButtonsToRemove": ["lasso2d", "toggleSpikelines"],
},
figure=humidity(0),
),
dcc.Graph(
id="live-auxInput",
animate=False,
config={
"displaylogo": False,
"scrollZoom": True,
"modeBarButtonsToRemove": ["lasso2d", "toggleSpikelines"],
},
figure=auxinput(0),
),
dcc.Interval(id="graph-update", interval=1 * 10000),
]
)
@app.callback(
Output("live-temperature", "figure"),
[Input("graph-update", "n_intervals"),
Input("lock-zoom", "value")],
[State("live-temperature", "relayoutData")],
)
def update_graph(value, lock_zoom, relayout_data):
new_figure = copy.deepcopy(temperature('n'))
new_figure["layout"]
# relayout_data contains data on the zoom and range actions
#print(relayout_data)
if relayout_data and lock_zoom == "Lock View":
if "xaxis.range[0]" in relayout_data:
new_figure["layout"]["xaxis"]["range"] = [
relayout_data["xaxis.range[0]"],
relayout_data["xaxis.range[1]"],
]
if "yaxis.range[0]" in relayout_data:
new_figure["layout"]["yaxis"]["range"] = [
relayout_data["yaxis.range[0]"],
relayout_data["yaxis.range[1]"],
]
return new_figure
@app.callback(
Output("live-humidity", "figure"),
[Input("graph-update", "n_intervals"),
Input("lock-zoom", "value")],
[State("live-humidity", "relayoutData")],
)
def update_graph(value, lock_zoom, relayout_data):
new_figure = copy.deepcopy(humidity('n'))
new_figure["layout"]
# relayout_data contains data on the zoom and range actions
#print(relayout_data)
if relayout_data and lock_zoom == "Lock View":
if "xaxis.range[0]" in relayout_data:
new_figure["layout"]["xaxis"]["range"] = [
relayout_data["xaxis.range[0]"],
relayout_data["xaxis.range[1]"],
]
if "yaxis.range[0]" in relayout_data:
new_figure["layout"]["yaxis"]["range"] = [
relayout_data["yaxis.range[0]"],
relayout_data["yaxis.range[1]"],
]
return new_figure
@app.callback(
Output("live-auxInput", "figure"),
[Input("graph-update", "n_intervals"),
Input("lock-zoom", "value")],
[State("live-auxInput", "relayoutData")],
)
def update_graph(value, lock_zoom, relayout_data):
new_figure = copy.deepcopy(auxinput('n'))
new_figure["layout"]
# relayout_data contains data on the zoom and range actions
#print(relayout_data)
if relayout_data and lock_zoom == "Lock View":
if "xaxis.range[0]" in relayout_data:
new_figure["layout"]["xaxis"]["range"] = [
relayout_data["xaxis.range[0]"],
relayout_data["xaxis.range[1]"],
]
if "yaxis.range[0]" in relayout_data:
new_figure["layout"]["yaxis"]["range"] = [
relayout_data["yaxis.range[0]"],
relayout_data["yaxis.range[1]"],
]
return new_figure
if __name__ == "__main__":
app.run_server(host="0.0.0.0", port=8051, debug=False)